Skip to content

Commit

Permalink
chore: add a generic error for limit's exeeded (#6452)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
gastonfournier committed Mar 6, 2024
1 parent 8a67640 commit feb6825
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions 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,
});
}
}
2 changes: 1 addition & 1 deletion src/lib/error/unleash-error.ts
Expand Up @@ -28,7 +28,7 @@ export const UnleashApiErrorTypes = [
'InvalidTokenError',
'OwaspValidationError',
'ForbiddenError',

'ExceedsLimitError',
// server errors; not the end user's fault
'InternalError',
] as const;
Expand Down

0 comments on commit feb6825

Please sign in to comment.