I'm working on blockchain based document verification system. The system works perfectly when there is a document issued by the user. The problem is when there is no issued document by the user(for example, when the user is new), the error is with the following code,
<% console.log('fit', JSON.parse(documents, null, '\t')) %>
When a document is issued by the user, it returns the following JSON data:
fit
[
{
Key: 'DOCUMENT0',
Record: {
name: 'bachelor of science degree',
url: 'https://bitcoin.org/ggg.pdf',
issuedBy: 'sol123',
dateOfIssuance: '12:18 PM, 25 September, 2021',
hashedDoc: 'dac729a8acf4b8a88f73f5bd84206c34e01e0992efa251b772f68696e2c2539c9ed0090e73ef6b87dc24e3177c6fd5341c3e9e24ef14267ce07ab9428aeed897',
docType: 'Whitepaper'
}
}
]
The problem is when a user creates account(signup) and login to the system for the first time or when there is no document issued by the user,it returns the following error:
SyntaxError: /home/bishoftu/fabcar/javascript/views/pages/dashboard.ejs:13
11|
12| <div class="list-group" id="list-tab" role="tablist" style="margin-top: 10px;">
13| <% console.log('fit', JSON.parse(documents, null, '\t')) %> 14|
Unexpected end of JSON input at JSON.parse ()
What i want is to display the message "NO DOCUMENT ISSUED", when there is no document issued by the user.
Put the JSON.parse() in a try/catch statement, and log a custom error if it fails:
try
{
let json = JSON.parse(documents, null, '\t');
console.log(json);
}
catch(error)
{
console.info("NO DOCUMENT ISSUED");
}