Skip to content

Commit

Permalink
Merge pull request #89 from TEAM-DAWM/refac/88
Browse files Browse the repository at this point in the history
[refac] 잘못된 api 요청 시 에러 코드 수정
  • Loading branch information
minwoo0419 authored Jul 16, 2024
2 parents 5997fb8 + 15e95aa commit caa913d
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ public ResponseEntity<NotFoundErrorCode> handleNotFoundException(NotFoundExcepti

// 존재하지 않는 요청에 대한 예외
@ExceptionHandler(value={NoHandlerFoundException.class, HttpRequestMethodNotSupportedException.class})
public ResponseEntity<NotFoundErrorCode> handleNoPageFoundException(Exception e) {
public ResponseEntity<BusinessErrorCode> handleNoPageFoundException(Exception e) {
log.error("GlobalExceptionHandler catch NoHandlerFoundException : {}", e.getMessage());
return ResponseEntity
.status(NotFoundErrorCode.NOT_FOUND_END_POINT.getHttpStatus())
.body(NotFoundErrorCode.NOT_FOUND_END_POINT);
.status(BusinessErrorCode.WRONG_ENTRY_POINT.getHttpStatus())
.body(BusinessErrorCode.WRONG_ENTRY_POINT);
}

// 기본 예외
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@Getter
@AllArgsConstructor
public enum BusinessErrorCode implements DefaultErrorCode{
WRONG_ENTRY_POINT(HttpStatus.BAD_REQUEST, "error", "잘못된 요청입니다."),
TIME_CONFLICT(HttpStatus.OK, "conflict", "시작 시간은 종료 시간 이전이어야 합니다."),
DUP_TIMEBLOCK_CONFLICT(HttpStatus.OK,"conflict","지정된 시간 범위 내에 이미 TimeBlock이 있습니다."),
DUP_DAY_TIMEBLOCK_CONFLICT(HttpStatus.OK, "conflict", "지정된 날짜의 작업에 대한 TimeBlock이 이미 있습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
@AllArgsConstructor
public enum NotFoundErrorCode implements DefaultErrorCode{
NOT_FOUND_TASK(HttpStatus.NOT_FOUND, "error", "존재하지 않는 Task입니다."),
NOT_FOUND_END_POINT(HttpStatus.NOT_FOUND, "error", "존재하지 않는 API입니다."),
NOT_FOUND_GOOGLE_CALENDER(HttpStatus.NOT_FOUND, "error", "존재하지 않는 구글 캘린더 입니다."),
NOT_FOUND_REFRESH_TOKEN(HttpStatus.NOT_FOUND, "error","RefreshToken을 찾을 수 없습니다."),
NOT_FOUND_USER(HttpStatus.NOT_FOUND,"error","존재하지 않는 사용자입니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
public enum UnAuthorizedErrorCode implements DefaultErrorCode{
TOKEN_EXPIRED_ERROR(HttpStatus.UNAUTHORIZED, "error", "만료된 토큰입니다."),
TOKEN_UNKNOWN_ERROR(HttpStatus.UNAUTHORIZED, "error", "인증 토큰이 존재지 않습니다."),
UNAUTHORIZED(HttpStatus.UNAUTHORIZED, "error", "인증되지 않은 사용자입니다."),
TOKEN_TYPE_ERROR(HttpStatus.UNAUTHORIZED, "error", "토큰 타입이 잘못되거나 제공되지 않았습니다."),
TOKEN_MALFORMED_ERROR(HttpStatus.UNAUTHORIZED, "error", "잘못된 형식의 토큰입니다."),
TOKEN_UNSUPPORTED_ERROR(HttpStatus.UNAUTHORIZED, "error", "지원되지 않는 토큰입니다."),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nutshell.server.security.filter;

import lombok.NonNull;
import nutshell.server.exception.BusinessException;
import nutshell.server.exception.code.DefaultErrorCode;
import nutshell.server.exception.code.InternalServerErrorCode;
import nutshell.server.exception.code.UnAuthorizedErrorCode;
Expand Down Expand Up @@ -40,6 +41,8 @@ protected void doFilterInternal(
handleException(request, response, filterChain, UnAuthorizedErrorCode.TOKEN_UNSUPPORTED_ERROR, e);
} catch (JwtException e) {
handleException(request, response, filterChain, UnAuthorizedErrorCode.TOKEN_UNKNOWN_ERROR, e);
} catch (BusinessException e) {
handleException(request, response, filterChain, e.getErrorCode(), e);
} catch (Exception e) {
handleException(request, response, filterChain, InternalServerErrorCode.INTERNAL_SERVER_ERROR, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import nutshell.server.dto.common.ResponseDto;
import nutshell.server.exception.code.BusinessErrorCode;
import nutshell.server.exception.code.DefaultErrorCode;
import nutshell.server.exception.code.UnAuthorizedErrorCode;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.core.AuthenticationException;
Expand All @@ -25,7 +25,7 @@ public void commence(
) throws IOException {
DefaultErrorCode errorCode = (DefaultErrorCode) request.getAttribute("exception");
if (errorCode == null)
errorCode = UnAuthorizedErrorCode.UNAUTHORIZED;
errorCode = BusinessErrorCode.WRONG_ENTRY_POINT;
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.setStatus(errorCode.getHttpStatus().value());
Expand Down

0 comments on commit caa913d

Please sign in to comment.