From 395037c44ea19fce477be1f58761508d105789dd Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Tue, 21 Mar 2023 15:24:14 +0200 Subject: [PATCH 1/2] Add ability to set options into AuthTokenGenerationError --- workers/loc.api/errors/index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/workers/loc.api/errors/index.js b/workers/loc.api/errors/index.js index f68dfc410..c28a293d1 100644 --- a/workers/loc.api/errors/index.js +++ b/workers/loc.api/errors/index.js @@ -6,6 +6,9 @@ const { ConflictError, ArgsParamsError } = require('bfx-report/workers/loc.api/errors') +const { + getErrorArgs +} = require('bfx-report/workers/loc.api/errors/helpers') class CollSyncPermissionError extends BaseError { constructor (message = 'ERR_PERMISSION_DENIED_TO_SYNC_SELECTED_COLL') { @@ -220,8 +223,10 @@ class SyncInfoUpdatingError extends BaseError { } class AuthTokenGenerationError extends AuthError { - constructor (message = 'ERR_AUTH_TOKEN_HAS_NOT_BEEN_GENERATED') { - super(message) + constructor (args) { + const _args = getErrorArgs(args, 'ERR_AUTH_TOKEN_HAS_NOT_BEEN_GENERATED') + + super(_args) } } From 5f480dd2971149f9379e151540af8ec8965449c2 Mon Sep 17 00:00:00 2001 From: Vladimir Voronkov Date: Tue, 21 Mar 2023 15:30:02 +0200 Subject: [PATCH 2/2] Add auth token invalid flag into AuthError --- workers/loc.api/sync/authenticator/index.js | 47 +++++++++++++-------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/workers/loc.api/sync/authenticator/index.js b/workers/loc.api/sync/authenticator/index.js index fa240fada..d2f54065e 100644 --- a/workers/loc.api/sync/authenticator/index.js +++ b/workers/loc.api/sync/authenticator/index.js @@ -1150,27 +1150,36 @@ class Authenticator { } async generateAuthToken (args) { - const opts = { - ttl: this.authTokenTTLSec, - writePermission: false - } + try { + const opts = { + ttl: this.authTokenTTLSec, + writePermission: false + } - const res = await this.getDataFromApi({ - getData: (s, args) => this.rService._generateToken(args, opts), - args, - callerName: 'AUTHENTICATOR', - eNetErrorAttemptsTimeframeMin: 10 / 60, - eNetErrorAttemptsTimeoutMs: 1000, - shouldNotInterrupt: true - }) + const res = await this.getDataFromApi({ + getData: (s, args) => this.rService._generateToken(args, opts), + args, + callerName: 'AUTHENTICATOR', + eNetErrorAttemptsTimeframeMin: 10 / 60, + eNetErrorAttemptsTimeoutMs: 1000, + shouldNotInterrupt: true + }) - const [authToken] = Array.isArray(res) ? res : [null] + const [authToken] = Array.isArray(res) ? res : [null] - if (!authToken) { - throw new AuthTokenGenerationError() - } + if (!authToken) { + throw new AuthTokenGenerationError() + } - return authToken + return authToken + } catch (err) { + throw new AuthTokenGenerationError({ + data: { + isAuthTokenGenerationError: true, + rootMessage: err.toString() + } + }) + } } async invalidateAuthToken (args) { @@ -1253,7 +1262,9 @@ class Authenticator { ) if (res?.changes < 1) { - throw new AuthTokenGenerationError() + throw new AuthTokenGenerationError({ + data: { isAuthTokenGenerationError: true } + }) } session.authToken = newAuthToken