Skip to content

Commit

Permalink
#327 feat: ExceptionAdvice 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
psyeon1120 committed Jul 11, 2024
1 parent 457ea93 commit a5a7bfe
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
import com.example.icebutler_server.global.dto.response.ResponseCustom;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.validation.FieldError;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;

import java.sql.SQLException;
import java.time.format.DateTimeParseException;
import java.util.Objects;

public class ExceptionAdvice {
Expand All @@ -25,4 +31,26 @@ protected ResponseCustom handleMethodArgumentNotValidException(MethodArgumentNot
ReturnCode returnCode = ReturnCode.findByCode(fieldError.getDefaultMessage());
return ResponseCustom.error(returnCode);
}

@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(
value = {
HttpMessageNotReadableException.class,
HttpRequestMethodNotSupportedException.class,
MissingServletRequestParameterException.class,
MethodArgumentTypeMismatchException.class,
DateTimeParseException.class
}
)
protected ResponseCustom handleBaseException(Exception e) {
return ResponseCustom.error(ReturnCode.INVALID_PARAM);
}

@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(
value = {SQLException.class}
)
protected ResponseCustom handleBaseException(SQLException e) {
return ResponseCustom.error(ReturnCode.INTERNAL_SERVER_ERROR);
}
}

0 comments on commit a5a7bfe

Please sign in to comment.