From ec7f4ed05e086ffe2306d489810220ee8ab18e96 Mon Sep 17 00:00:00 2001 From: Pierre Troger Date: Wed, 4 Sep 2024 11:06:28 +0200 Subject: [PATCH 1/2] default to unknown errors, safe big int to be explicit about the error --- .../service/authorization-request.service.ts | 16 ++++++++++++++-- .../authorization-request.repository.ts | 4 ++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/apps/armory/src/orchestration/core/service/authorization-request.service.ts b/apps/armory/src/orchestration/core/service/authorization-request.service.ts index d4823572c..3f70313b3 100644 --- a/apps/armory/src/orchestration/core/service/authorization-request.service.ts +++ b/apps/armory/src/orchestration/core/service/authorization-request.service.ts @@ -123,6 +123,19 @@ export class AuthorizationRequestService { return this.authzRequestRepository.findById(requestId) } + safeBigInt(value: string | number): bigint { + try { + return BigInt(value) + } catch (error) { + throw new ApplicationException({ + message: 'Invalid BigInt value', + context: { value }, + origin: error, + suggestedHttpStatusCode: HttpStatus.BAD_REQUEST + }) + } + } + async evaluate(input: AuthorizationRequest): Promise { this.logger.log('Start authorization request evaluation', { requestId: input.id, @@ -165,7 +178,6 @@ export class AuthorizationRequestService { suggestedHttpStatusCode: HttpStatus.BAD_REQUEST }) } - const transfer = { resourceId: input.request.resourceId, clientId: input.clientId, @@ -176,7 +188,7 @@ export class AuthorizationRequestService { chainId: input.request.transactionRequest.chainId, initiatedBy: evaluation.principal?.userId, createdAt: new Date(), - amount: BigInt(intent.amount), + amount: this.safeBigInt(intent.amount), rates: transferPrices[intent.token] || {} } diff --git a/apps/armory/src/orchestration/persistence/repository/authorization-request.repository.ts b/apps/armory/src/orchestration/persistence/repository/authorization-request.repository.ts index 7db8281e3..04f7f81b2 100644 --- a/apps/armory/src/orchestration/persistence/repository/authorization-request.repository.ts +++ b/apps/armory/src/orchestration/persistence/repository/authorization-request.repository.ts @@ -132,8 +132,8 @@ export class AuthorizationRequestRepository { return errors.map((error) => ({ id: error.id, clientId, - name: error.name, - message: error.message + name: error.name || 'Unknown error', + message: error.message || '' })) } From 6ae1010c86b37e0fd0474ed590773474713c3628 Mon Sep 17 00:00:00 2001 From: Pierre Troger Date: Wed, 4 Sep 2024 11:10:20 +0200 Subject: [PATCH 2/2] renamed fn --- .../core/service/authorization-request.service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/armory/src/orchestration/core/service/authorization-request.service.ts b/apps/armory/src/orchestration/core/service/authorization-request.service.ts index 3f70313b3..41d7b9e17 100644 --- a/apps/armory/src/orchestration/core/service/authorization-request.service.ts +++ b/apps/armory/src/orchestration/core/service/authorization-request.service.ts @@ -123,7 +123,7 @@ export class AuthorizationRequestService { return this.authzRequestRepository.findById(requestId) } - safeBigInt(value: string | number): bigint { + bigIntWithError(value: string | number): bigint { try { return BigInt(value) } catch (error) { @@ -188,7 +188,7 @@ export class AuthorizationRequestService { chainId: input.request.transactionRequest.chainId, initiatedBy: evaluation.principal?.userId, createdAt: new Date(), - amount: this.safeBigInt(intent.amount), + amount: this.bigIntWithError(intent.amount), rates: transferPrices[intent.token] || {} }