Spring관련 기술/서버개발

MethodArgumentTypeMismatchException

솜사탕코튼 2024. 8. 30. 23:28

MethodArgumentTypeMismatchException

 

파라미터의 Type(형식)이 제대로 넘어오지 않았을 때.

 

LocalDate 타입으로 넘어와야하는데 String이나 int로 넘어온 경우

 

    @ExceptionHandler(MethodArgumentTypeMismatchException.class)
    public ResponseEntity<ErrorResponse> handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e) {
        log.error("MethodArgumentTypeMismatch Exception occurred. message={}", e.getMessage());
        return ResponseEntity.status(HttpStatus.BAD_REQUEST)
                .body(new ErrorResponse(ErrorType.INVALID_PARAMETER.getDescription(), ErrorType.INVALID_PARAMETER));
    }