From bc3478da5277391e98a802826960f4224e19c50a Mon Sep 17 00:00:00 2001 From: Viktar <1105714@gmail.com> Date: Wed, 20 Jul 2022 08:30:24 +0400 Subject: [PATCH] - rework create check exception handling, add the body to the error message --- .eslintrc.yaml | 2 ++ SyngrisiDriver.js | 25 +++++++++++-------------- lib/api.js | 4 ++-- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/.eslintrc.yaml b/.eslintrc.yaml index dea3946..ccbc47b 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -4,6 +4,8 @@ env: extends: - 'airbnb-base' + - "eslint:recommended" + globals: assert: true diff --git a/SyngrisiDriver.js b/SyngrisiDriver.js index 0bea7fe..dd18628 100644 --- a/SyngrisiDriver.js +++ b/SyngrisiDriver.js @@ -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; @@ -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; } } diff --git a/lib/api.js b/lib/api.js index 47fe05f..6408a46 100644 --- a/lib/api.js +++ b/lib/api.js @@ -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); } } }