From 43a9364b76fce69dc857233534f295791b62fb1d Mon Sep 17 00:00:00 2001 From: zulfikarrosadi Date: Thu, 21 Nov 2024 10:47:01 +0700 Subject: [PATCH] fix(update product): add handling error when converting string to Bigint --- src/product/service.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/product/service.ts b/src/product/service.ts index 2abf606..9b10e87 100644 --- a/src/product/service.ts +++ b/src/product/service.ts @@ -151,8 +151,8 @@ class ProductService { id: string, data: UpdateProductDataService, ): Promise> => { - const parsedId = BigInt(id) try { + const parsedId = BigInt(id) if (Number.isNaN(parsedId)) { throw new NotFoundError( "you are trying to update the product that doesn't exists", @@ -197,6 +197,15 @@ class ProductService { 'updateProductById', context, ) + if (error instanceof SyntaxError) { + return { + status: 'fail', + errors: { + code: 404, + message: 'fail to update product, product not found', + }, + } + } return { status: 'fail', errors: {