feat: improve error handling with proper HTTP status codes

This commit is contained in:
litoral05
2026-05-05 16:05:03 +01:00
parent 7124171278
commit 690209547b
@@ -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");
}
}