Skip to content

Commit f757536

Browse files
Catch errors when the server reply is not JSON (#22)
* Update HelperMethods.js * Update Co-Authored-By: Jorn Verhoeven <jorn.j.verhoeven@gmail.com> * Update HelperMethods.js Co-Authored-By: Jorn Verhoeven <jorn.j.verhoeven@gmail.com> Co-authored-by: Jorn Verhoeven <jorn.j.verhoeven@gmail.com>
1 parent bb0caeb commit f757536

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

internal/HelperMethods.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@ module.exports = class HelperMethods {
4343
}
4444
} catch(error){
4545
if (error.name === "HTTPError") {
46-
reject(new Error(JSON.parse(error.response.body).message));
46+
try {
47+
reject(new Error(JSON.parse(error.response.body).message));
48+
} catch (e) {
49+
reject(new Error("Could not parse the error message returned from the server. "+
50+
"If this error persists, please check that the LicenseServerUrl does not end with '/'. "+
51+
"E.g. 'https://api.cryptolens.io' is correct whereas 'https://api.cryptolens.io/' is not."));
52+
}
4753
} else {
4854
reject(error);
4955
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "cryptolens",
3-
"version": "1.0.7",
4-
"description": "Client API for NodeJS to access Cryptolens Software Licensing API",
3+
"version": "1.0.8",
4+
"description": "Client API for NodeJS to access Cryptolens Software Licensing API.",
55
"main": "main.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1"

0 commit comments

Comments
 (0)