diff --git a/src/main/java/org/cmh/backend/Utils/GlobalExceptionHandler.java b/src/main/java/org/cmh/backend/Utils/GlobalExceptionHandler.java index b513f14..e9d8af5 100644 --- a/src/main/java/org/cmh/backend/Utils/GlobalExceptionHandler.java +++ b/src/main/java/org/cmh/backend/Utils/GlobalExceptionHandler.java @@ -2,9 +2,15 @@ package org.cmh.backend.Utils; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.http.converter.HttpMessageNotReadableException; +import org.springframework.web.bind.MissingServletRequestParameterException; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + @ControllerAdvice public class GlobalExceptionHandler { @@ -12,4 +18,17 @@ public class GlobalExceptionHandler { public ResponseEntity handleJwtInvalidException(JwtValidationException ex) { return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); } + + @ExceptionHandler(MissingServletRequestParameterException.class) + public ResponseEntity> handleMissingServletRequestParameterException(MissingServletRequestParameterException ex) { + HashMap response = new HashMap<>(); + response.put("error", ex.getMessage()); + response.put("stackTrace", Arrays.toString(ex.getStackTrace())); + return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST); + } + + @ExceptionHandler(HttpMessageNotReadableException.class) + public ResponseEntity handleHttpMessageNotReadableException(HttpMessageNotReadableException ex) { + return new ResponseEntity<>(ex.getMessage(), HttpStatus.BAD_REQUEST); + } } \ No newline at end of file