Skip to content

Commit 0bfe6b0

Browse files
authored
[BACKEND] Exception 처리 및 도메인 추가 (#107)
1 parent 499ed96 commit 0bfe6b0

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

backend/src/main/java/com/cmg/comtogether/common/config/CorsConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ public CorsConfigurationSource corsConfigurationSource() {
1616
configuration.setAllowedOrigins(Arrays.asList(
1717
"http://localhost:3000",
1818
"https://com-together.vercel.app",
19-
"https://com-together.org"
19+
"https://com-together.org",
20+
"https://comtogetherofficial.vercel.app"
2021
)); // 프론트 도메인
2122
configuration.addAllowedMethod("*"); // 모든 HTTP 메서드 허용
2223
configuration.addAllowedHeader("*"); // 모든 헤더 허용

backend/src/main/java/com/cmg/comtogether/common/exception/ErrorCode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public enum ErrorCode {
1010
// 공통
1111
INVALID_INPUT(400, "COMMON-001", "잘못된 입력 값입니다."),
1212
INVALID_FORMAT(400, "COMMON-002", "요청 본문의 형식이 올바르지 않습니다."),
13+
METHOD_NOT_ALLOWED(405, "COMMON-003", "지원하지 않는 메서드입니다."),
1314
INTERNAL_SERVER_ERROR(500, "COMMON-999", "서버 에러가 발생했습니다."),
1415

1516
// 유저

backend/src/main/java/com/cmg/comtogether/common/exception/GlobalExceptionHandler.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.springframework.http.ResponseEntity;
66
import org.springframework.http.converter.HttpMessageNotReadableException;
77
import org.springframework.validation.FieldError;
8+
import org.springframework.web.HttpRequestMethodNotSupportedException;
89
import org.springframework.web.bind.MethodArgumentNotValidException;
910
import org.springframework.web.bind.MissingServletRequestParameterException;
1011
import org.springframework.web.bind.annotation.ExceptionHandler;
@@ -54,6 +55,25 @@ public ResponseEntity<ErrorResponse> handleHttpMessageNotReadable(HttpMessageNot
5455
.body(ErrorResponse.of(ErrorCode.INVALID_FORMAT, ErrorCode.INVALID_FORMAT.getMessage()));
5556
}
5657

58+
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
59+
public ResponseEntity<ErrorResponse> handleMethodNotSupported(HttpRequestMethodNotSupportedException e) {
60+
61+
String method = e.getMethod();
62+
String supported = (e.getSupportedMethods() != null)
63+
? String.join(", ", e.getSupportedMethods())
64+
: "N/A";
65+
66+
String message = String.format(
67+
"요청 메서드 '%s' 는 지원되지 않습니다. 가능한 메서드: [%s]",
68+
method, supported
69+
);
70+
71+
return ResponseEntity
72+
.status(ErrorCode.METHOD_NOT_ALLOWED.getStatus())
73+
.body(ErrorResponse.of(ErrorCode.METHOD_NOT_ALLOWED, message));
74+
}
75+
76+
5777
@ExceptionHandler(BusinessException.class)
5878
public ResponseEntity<ErrorResponse> handleBusinessException(BusinessException e) {
5979
ErrorCode errorCode = e.getErrorCode();

0 commit comments

Comments
 (0)