Skip to content

Commit f0794a0

Browse files
committed
feat: 필수 헤더가 없을 경우 발생하는 에러 핸들링 구현
1 parent 5755252 commit f0794a0

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/main/java/timeeat/exception/EtcErrorCode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public enum EtcErrorCode {
1313
MEDIA_TYPE_NOT_SUPPORTED("CLIENT005", "허용되지 않은 미디어 타입입니다.", HttpStatus.UNSUPPORTED_MEDIA_TYPE),
1414
NO_RESOURCE_FOUND("CLIENT006", "요청한 리소스를 찾을 수 없습니다.", HttpStatus.NOT_FOUND),
1515
NO_COOKIE_FOUND("CLIENT007", "필수 쿠키 값이 존재하지 않습니다.", HttpStatus.BAD_REQUEST),
16+
NO_HEADER_FOUND("CLIENT007", "필수 헤더 값이 존재하지 않습니다.", HttpStatus.BAD_REQUEST),
1617

1718
INTERNAL_SERVER_ERROR("SERVER001", "서버 내부 에러가 발생했습니다.", HttpStatus.INTERNAL_SERVER_ERROR),
1819
;

src/main/java/timeeat/exception/GlobalExceptionHandler.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.springframework.web.HttpMediaTypeNotSupportedException;
99
import org.springframework.web.HttpRequestMethodNotSupportedException;
1010
import org.springframework.web.bind.MissingRequestCookieException;
11+
import org.springframework.web.bind.MissingRequestHeaderException;
1112
import org.springframework.web.bind.annotation.ExceptionHandler;
1213
import org.springframework.web.bind.annotation.RestControllerAdvice;
1314
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
@@ -62,6 +63,11 @@ public ResponseEntity<ErrorResponse> handleMissingRequestCookieException(Missing
6263
return toErrorResponse(EtcErrorCode.NO_COOKIE_FOUND);
6364
}
6465

66+
@ExceptionHandler(MissingRequestHeaderException.class)
67+
public ResponseEntity<ErrorResponse> handleMissingRequestHeaderException(MissingRequestHeaderException exception) {
68+
return toErrorResponse(EtcErrorCode.NO_HEADER_FOUND);
69+
}
70+
6571
@ExceptionHandler(BusinessException.class)
6672
public ResponseEntity<ErrorResponse> handleBusinessException(BusinessException exception) {
6773
ErrorResponse response = new ErrorResponse(exception.getErrorCode());

0 commit comments

Comments
 (0)