Skip to content

Commit

Permalink
chore: remove the try/catch block
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Burtey committed Sep 25, 2023
1 parent 0e24b42 commit 3c4b262
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/graphql/error-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
26 changes: 9 additions & 17 deletions src/servers/middlewares/idempotency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 3c4b262

Please sign in to comment.