From feb682502353afb6d3e786251fceebede558e403 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gast=C3=B3n=20Fournier?= Date: Wed, 6 Mar 2024 19:17:31 +0100 Subject: [PATCH] chore: add a generic error for limit's exeeded (#6452) ## About the changes We don't have a meaningful error for limits established by the application. This could be a good starting point. The error code is 400 cause I couldn't find anything better. The name of the error was picked from UnleashApiErrorTypes: https://github.com/Unleash/unleash/blob/2d8e9f87ff96fcb2e2f84a8b4b36bf5c0e28a885/src/lib/error/unleash-error.ts#L4-L34 --- src/lib/error/exceeds-limit-error.ts | 11 +++++++++++ src/lib/error/unleash-error.ts | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/lib/error/exceeds-limit-error.ts diff --git a/src/lib/error/exceeds-limit-error.ts b/src/lib/error/exceeds-limit-error.ts new file mode 100644 index 0000000000..bb5a24c41f --- /dev/null +++ b/src/lib/error/exceeds-limit-error.ts @@ -0,0 +1,11 @@ +import { GenericUnleashError } from './unleash-error'; + +export class ExceedsLimitError extends GenericUnleashError { + constructor(resource: string, limit: number) { + super({ + name: 'ExceedsLimitError', + message: `Failed to create ${resource}. You can't create more than the established limit of ${limit}.`, + statusCode: 400, + }); + } +} diff --git a/src/lib/error/unleash-error.ts b/src/lib/error/unleash-error.ts index 565808a48b..3d4741354d 100644 --- a/src/lib/error/unleash-error.ts +++ b/src/lib/error/unleash-error.ts @@ -28,7 +28,7 @@ export const UnleashApiErrorTypes = [ 'InvalidTokenError', 'OwaspValidationError', 'ForbiddenError', - + 'ExceedsLimitError', // server errors; not the end user's fault 'InternalError', ] as const;