|
@@ -4,8 +4,8 @@ import com.pharmacopoeia.dto.ApiResponse;
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.HttpStatus;
|
|
|
-import org.springframework.http.ResponseEntity;
|
|
|
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
|
|
|
+import org.springframework.web.bind.annotation.ResponseStatus;
|
|
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|
|
|
|
|
|
|
@RestControllerAdvice
|
|
@RestControllerAdvice
|
|
@@ -14,22 +14,22 @@ public class GlobalExceptionHandler {
|
|
|
private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
|
|
private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
|
|
|
|
|
|
|
|
@ExceptionHandler(IllegalArgumentException.class)
|
|
@ExceptionHandler(IllegalArgumentException.class)
|
|
|
- public ResponseEntity<ApiResponse<Void>> handleBadRequest(IllegalArgumentException e) {
|
|
|
|
|
- return ResponseEntity.status(HttpStatus.BAD_REQUEST)
|
|
|
|
|
- .body(ApiResponse.error(400, e.getMessage()));
|
|
|
|
|
|
|
+ @ResponseStatus(HttpStatus.BAD_REQUEST)
|
|
|
|
|
+ public ApiResponse<Void> handleBadRequest(IllegalArgumentException e) {
|
|
|
|
|
+ return ApiResponse.error(400, e.getMessage());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@ExceptionHandler(RuntimeException.class)
|
|
@ExceptionHandler(RuntimeException.class)
|
|
|
- public ResponseEntity<ApiResponse<Void>> handleRuntime(RuntimeException e) {
|
|
|
|
|
|
|
+ @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
|
|
|
+ public ApiResponse<Void> handleRuntime(RuntimeException e) {
|
|
|
log.error("Runtime error: {}", e.getMessage(), e);
|
|
log.error("Runtime error: {}", e.getMessage(), e);
|
|
|
- return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
|
|
|
- .body(ApiResponse.error(500, e.getMessage()));
|
|
|
|
|
|
|
+ return ApiResponse.error(500, e.getMessage());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@ExceptionHandler(Exception.class)
|
|
@ExceptionHandler(Exception.class)
|
|
|
- public ResponseEntity<ApiResponse<Void>> handleGeneral(Exception e) {
|
|
|
|
|
|
|
+ @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
|
|
|
+ public ApiResponse<Void> handleGeneral(Exception e) {
|
|
|
log.error("Unexpected error: {}", e.getMessage(), e);
|
|
log.error("Unexpected error: {}", e.getMessage(), e);
|
|
|
- return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
|
|
|
- .body(ApiResponse.error(500, "Internal server error"));
|
|
|
|
|
|
|
+ return ApiResponse.error(500, "Internal server error");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|