feat: improve error handling with proper HTTP status codes
This commit is contained in:
@@ -15,9 +15,22 @@ public class ApiExceptionHandler {
|
||||
return Map.of("error", exception.getMessage());
|
||||
}
|
||||
|
||||
@ResponseStatus(HttpStatus.CONFLICT)
|
||||
@ExceptionHandler(IllegalStateException.class)
|
||||
public Map<String, String> handleIllegalState(IllegalStateException exception) {
|
||||
return Map.of("error", exception.getMessage());
|
||||
}
|
||||
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||
public Map<String, String> handleValidation(MethodArgumentNotValidException exception) {
|
||||
return Map.of("error", "Validation failed");
|
||||
}
|
||||
|
||||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
@ExceptionHandler(Exception.class)
|
||||
public Map<String, String> handleGeneric(Exception exception) {
|
||||
return Map.of("error", "Internal server error");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user