Skip to content

Commit 910f1b7

Browse files
committed
feat(error): add specific exception mappings
- Added mappings for new exceptions - Improved error code consistency
1 parent c5af9e3 commit 910f1b7

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/src/middlewares/error_handler.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,27 +63,33 @@ Middleware errorHandler() {
6363
/// Maps HtHttpException subtypes to appropriate HTTP status codes.
6464
int _mapExceptionToStatusCode(HtHttpException exception) {
6565
return switch (exception) {
66+
InvalidInputException() => HttpStatus.badRequest, // 400
67+
AuthenticationException() => HttpStatus.unauthorized, // 401
6668
BadRequestException() => HttpStatus.badRequest, // 400
6769
UnauthorizedException() => HttpStatus.unauthorized, // 401
6870
ForbiddenException() => HttpStatus.forbidden, // 403
6971
NotFoundException() => HttpStatus.notFound, // 404
7072
ServerException() => HttpStatus.internalServerError, // 500
73+
OperationFailedException() => HttpStatus.internalServerError, // 500
7174
NetworkException() => HttpStatus.serviceUnavailable, // 503 (or 500)
7275
UnknownException() => HttpStatus.internalServerError, // 500
73-
_ => HttpStatus.internalServerError,
76+
_ => HttpStatus.internalServerError, // Default
7477
};
7578
}
7679

7780
/// Maps HtHttpException subtypes to consistent error code strings.
7881
String _mapExceptionToCodeString(HtHttpException exception) {
7982
return switch (exception) {
83+
InvalidInputException() => 'INVALID_INPUT',
84+
AuthenticationException() => 'AUTHENTICATION_FAILED',
8085
BadRequestException() => 'BAD_REQUEST',
8186
UnauthorizedException() => 'UNAUTHORIZED',
8287
ForbiddenException() => 'FORBIDDEN',
8388
NotFoundException() => 'NOT_FOUND',
8489
ServerException() => 'SERVER_ERROR',
90+
OperationFailedException() => 'OPERATION_FAILED',
8591
NetworkException() => 'NETWORK_ERROR',
8692
UnknownException() => 'UNKNOWN_ERROR',
87-
_ => 'UNKNOWN_ERROR',
93+
_ => 'UNKNOWN_ERROR', // Default
8894
};
8995
}

0 commit comments

Comments
 (0)