From 3c4b262ea8f34725223578c9a1bd49bde6dbd415 Mon Sep 17 00:00:00 2001 From: Nicolas Burtey Date: Mon, 25 Sep 2023 12:00:25 +0100 Subject: [PATCH] chore: remove the try/catch block --- src/graphql/error-map.ts | 3 ++- src/servers/middlewares/idempotency.ts | 26 +++++++++----------------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/graphql/error-map.ts b/src/graphql/error-map.ts index bf3aade1238..b0bb2bc099a 100644 --- a/src/graphql/error-map.ts +++ b/src/graphql/error-map.ts @@ -499,7 +499,8 @@ export const mapError = (error: ApplicationError): CustomApolloError => { case "CouldNotFindLnPaymentFromHashError": case "LockError": case "LockServiceError": - case "ResourceAttemptsLockServiceError": + case "ResourceAttemptsRedlockServiceError": + case "ResourceAttemptsTimelockServiceError": case "ResourceExpiredLockServiceError": case "PriceError": case "PriceServiceError": diff --git a/src/servers/middlewares/idempotency.ts b/src/servers/middlewares/idempotency.ts index d453b6b66c6..e907c002a90 100644 --- a/src/servers/middlewares/idempotency.ts +++ b/src/servers/middlewares/idempotency.ts @@ -70,25 +70,17 @@ export const idempotencyMiddleware = async ( const idempotencyKeyMaybeSuffix = (idempotencyKey + (isPersistedQueryWithExtension ? "-persisted" : "")) as IdempotencyKey - try { - await lockService.lockIdempotencyKey(idempotencyKeyMaybeSuffix) - addAttributesToCurrentSpan({ idempotencyKey }) + const result = await lockService.lockIdempotencyKey(idempotencyKeyMaybeSuffix) + addAttributesToCurrentSpan({ idempotencyKey }) - next() - } catch (error) { - recordExceptionInCurrentSpan({ - error, - fallbackMsg: "Error locking idempotency key", - level: ErrorLevel.Critical, - }) - if (error instanceof ResourceAttemptsTimelockServiceError) { - return res.status(409).json({ error: "the idempotency key already exist" }) - } - if (error instanceof Error) { - return res.status(500).json({ error: error.message }) - } - return res.status(500).json({ error: "Unknown error in idempotency middleware" }) + if (result instanceof ResourceAttemptsTimelockServiceError) { + return res.status(409).json({ error: "the idempotency key already exist" }) } + if (result instanceof Error) { + return res.status(500).json({ error: result.message }) + } + + next() }) } else { next()