Skip to content

Commit 6275068

Browse files
committed
Update license_check.js
1 parent 3e8f27e commit 6275068

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

examples/license_check.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ let nonce = "%%__NONCE__%%";
1111
let timestamp = "%%__TIMESTAMP__%%";
1212

1313
async function main() {
14+
// Initialise wrapper and exit if a failure occurs.
1415
let init = await wrapper.init(token);
1516
if (init.result === "error") {
1617
console.log(init.error);
@@ -21,21 +22,19 @@ async function main() {
2122
let validated = await wrapper.resources.licenses.validate(resource_id, purchaser_id, fields);
2223

2324
if (validated.result === "error") {
24-
console.log(`Failed to check license due to API Error: ${validated.error}.`);
25-
console.log("Exiting...");
26-
process.exit(0);
27-
}
25+
if (validated.error.code === "ContentNotFoundError") {
26+
console.log("No license was found for this user. Exiting...");
27+
} else {
28+
console.log(`Failed to check license due to API Error: ${validated.error}.`);
29+
console.log("Exiting...");
30+
}
2831

29-
if (!validated.data) {
30-
console.log("No active license was found. Exiting...");
3132
process.exit(0);
32-
return;
3333
}
3434

3535
if (!validated.data.active) {
3636
console.log("A license has been found, but it's been disabled. Exiting...");
3737
process.exit(0);
38-
return;
3938
}
4039

4140
console.log("Active license found, returning from function without exiting.");

0 commit comments

Comments
 (0)