From 690209547b6d33028682f1b753eba8f117f2e526 Mon Sep 17 00:00:00 2001 From: litoral05 Date: Tue, 5 May 2026 16:05:03 +0100 Subject: [PATCH] feat: improve error handling with proper HTTP status codes --- .../openvpn/common/ApiExceptionHandler.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/com/litoralregas/openvpn/common/ApiExceptionHandler.java b/src/main/java/com/litoralregas/openvpn/common/ApiExceptionHandler.java index b9e7ef5..5fd7ca0 100644 --- a/src/main/java/com/litoralregas/openvpn/common/ApiExceptionHandler.java +++ b/src/main/java/com/litoralregas/openvpn/common/ApiExceptionHandler.java @@ -15,9 +15,22 @@ public class ApiExceptionHandler { return Map.of("error", exception.getMessage()); } + @ResponseStatus(HttpStatus.CONFLICT) + @ExceptionHandler(IllegalStateException.class) + public Map handleIllegalState(IllegalStateException exception) { + return Map.of("error", exception.getMessage()); + } + @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(MethodArgumentNotValidException.class) public Map handleValidation(MethodArgumentNotValidException exception) { return Map.of("error", "Validation failed"); } + + @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) + @ExceptionHandler(Exception.class) + public Map handleGeneric(Exception exception) { + return Map.of("error", "Internal server error"); + } + } \ No newline at end of file