Skip to content

Commit

Permalink
- rework create check exception handling, add the body to the error m…
Browse files Browse the repository at this point in the history
…essage
  • Loading branch information
viktor-silakov committed Jul 20, 2022
1 parent 950d01c commit bc3478d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ env:

extends:
- 'airbnb-base'
- "eslint:recommended"


globals:
assert: true
Expand Down
25 changes: 11 additions & 14 deletions SyngrisiDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class SyngrisiDriver {
version = browser.capabilities?.browserVersion || browser.capabilities?.version;
}
if (!version) {
// eslint-disable-next-line max-len
throw new Error('Cannot get Browser Version, try to check "capabilities.version", "capabilities.platformVersion" or "capabilities.browserVersion"');
}
return version;
Expand Down Expand Up @@ -260,27 +261,23 @@ class SyngrisiDriver {
);
return $this.coreCheck(imageBuffer, opts, apikey);
} catch (e) {
throw new Error(`Cannot create check with name: '${checkName}', parameters: '${JSON.stringify(opts)}, error: '${e + e.stack}'`);
throw new Error(`cannot create check, parameters: '${JSON.stringify(opts)}, error: '${e.stack || e}'`);
}
}

async coreCheck(imageBuffer, params, apikey) {
const $this = this;
try {
let resultWithHash = await $this.api.createCheck(params, false, params.hashCode, apikey);
resultWithHash = $this.addMessageIfCheckFailed(resultWithHash);
let resultWithHash = await $this.api.createCheck(params, false, params.hashCode, apikey);
resultWithHash = $this.addMessageIfCheckFailed(resultWithHash);

log.info(`Check result Phase #1: ${utils.prettyCheckResult(resultWithHash)}`);
if (resultWithHash.status === 'requiredFileData') {
let resultWithFile = await $this.api.createCheck(params, imageBuffer, params.hashCode, apikey);
log.info(`Check result Phase #2: ${utils.prettyCheckResult(resultWithFile)}`);
resultWithFile = $this.addMessageIfCheckFailed(resultWithFile);
return resultWithFile;
}
return resultWithHash;
} catch (e) {
throw new Error(`error in coreCheck: '${e + e.stack}'`);
log.info(`Check result Phase #1: ${utils.prettyCheckResult(resultWithHash)}`);
if (resultWithHash.status === 'requiredFileData') {
let resultWithFile = await $this.api.createCheck(params, imageBuffer, params.hashCode, apikey);
log.info(`Check result Phase #2: ${utils.prettyCheckResult(resultWithFile)}`);
resultWithFile = $this.addMessageIfCheckFailed(resultWithFile);
return resultWithFile;
}
return resultWithHash;
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ class SyngrisiApi {
return result;
} catch (e) {
utils.printErrorResponseBody(e);
throw new Error(`Cannot createCheck (post data) with url: '${url}', parameters: '${JSON.stringify(params)}', error: '${e + e.stack}'`);
throw new Error(`fait to post data, response body: ${e.response?.body} \n '${e.stack || e}'`);
}
} catch (e) {
throw new Error(`Cannot createCheck with parameters: '${JSON.stringify(params)}', error: '${e + e.stack}'`);
throw new Error(e);
}
}
}
Expand Down

0 comments on commit bc3478d

Please sign in to comment.