KEEPER31337 / Homepage-Back

키퍼 홈페이지 백엔드

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ExceptionAdvice가 보내는 status를 적절하게 바꾼다.

gusah009 opened this issue · comments

사전 수행 issue

없음.

이슈 내용

현재 ExceptionAdvice 코드를 살펴보면, 아래와 같이 @ResponseStatus5xx에러를 보내고 있는 것을 확인할 수 있습니다.

// ExceptionAdvice
@ExceptionHandler(CustomLoginIdSigninFailedException.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
protected CommonResult signInFailed(HttpServletRequest request,
    CustomLoginIdSigninFailedException e) {
  return responseService.getFailResult(Integer.parseInt(getMessage("SigninFailed.code")),
      e.getMessage() == null ? getMessage("SigninFailed.msg") : e.getMessage());
}

위의 경우, 로그인 ID 혹은 PW가 잘못되어 실행되는 Exception인데, 이건 서버의 에러라고 볼 수 없습니다. 사용자의 잘못된 요청으로 보는 것이 맞고, 400 BAD REQUEST status를 내보내는 것이 더 합당합니다.

이와 같이 잘못된 status를 보내고 있는 코드를 RESTful API 규칙에 따라 수정해야 합니다.

❗️되도록이면 5xx에러는 내보내지 않는 것이 좋습니다!

status 코드를 수정하는 방법 외에 이와 같은 방법도 있습니다!

이슈 수행 사항

  • 잘못된 status를 보내고 있는 코드를 RESTful API 규칙에 따라 수정한다.
  • ❗️혹여나 FE에서 해당 status code로 어떤 작업을 하고 있을 수 있기 때문에, 바뀐 내용에 대해선 반드시 FE에 알린다.