Skip to content

Commit b7e6faa

Browse files
committed
fix(error_handler): map rate limiting errors to 429 status code
- Add special case for ForbiddenException containing 'too many requests' - Map to 429 Too Many Requests status code for rate limiting errors
1 parent 167af20 commit b7e6faa

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/src/middlewares/error_handler.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ Middleware errorHandler() {
6666

6767
/// Maps HttpException subtypes to appropriate HTTP status codes.
6868
int _mapExceptionToStatusCode(HttpException exception) {
69+
// Special case for rate limiting
70+
if (exception is ForbiddenException &&
71+
exception.message.contains('too many requests')) {
72+
return 429; // Too Many Requests
73+
}
74+
6975
return switch (exception) {
7076
InvalidInputException() => HttpStatus.badRequest, // 400
7177
AuthenticationException() => HttpStatus.unauthorized, // 401

0 commit comments

Comments
 (0)