Skip to content

Commit fbbe24c

Browse files
authored
Merge pull request #197 from Gathering-Organization/be/feat/auth
[feat] 계정 연동 필요 시 200 OK를 반환하도록 예외 처리 수정
2 parents fd221cf + e314f3e commit fbbe24c

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Gathering_be/src/main/java/com/Gathering_be/global/exception/GlobalExceptionHandler.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.Gathering_be.global.exception;
22

33
import com.Gathering_be.global.response.ErrorResponse;
4+
import com.Gathering_be.global.response.ResultResponse;
45
import jakarta.servlet.http.HttpServletRequest;
56
import lombok.extern.slf4j.Slf4j;
67
import jakarta.validation.ConstraintViolationException;
@@ -210,8 +211,14 @@ protected ResponseEntity<ErrorResponse> handleHttpRequestMethodNotSupportedExcep
210211
}
211212

212213
@ExceptionHandler
213-
protected ResponseEntity<ErrorResponse> handleBusinessException(BusinessException e) {
214+
protected ResponseEntity<?> handleBusinessException(BusinessException e) {
214215
ErrorCode errorCode = e.getErrorCode();
216+
217+
if (errorCode == ACCOUNT_NEEDS_LINKING) {
218+
log.info("Account linking required for email : {}", e.getMessage());
219+
return ResponseEntity.ok(ResultResponse.of(errorCode));
220+
}
221+
215222
ErrorResponse response = ErrorResponse.of(errorCode, e.getErrors());
216223
logError(e, response);
217224

Gathering_be/src/main/java/com/Gathering_be/global/response/ResultResponse.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.Gathering_be.global.response;
22

3+
import com.Gathering_be.global.exception.ErrorCode;
34
import lombok.Getter;
45

56
@Getter
@@ -17,11 +18,20 @@ public ResultResponse(ResultCode resultCode, Object data) {
1718
this.data = data;
1819
}
1920

21+
public ResultResponse(ErrorCode errorCode, Object data) {
22+
this.status = errorCode.getStatus();
23+
this.code = errorCode.getCode();
24+
this.message = errorCode.getMessage();
25+
this.data = data;
26+
}
27+
2028
public static ResultResponse of(ResultCode resultCode, Object data) {
2129
return new ResultResponse(resultCode, data);
2230
}
2331

2432
public static ResultResponse of(ResultCode resultCode) {
2533
return new ResultResponse(resultCode, "");
2634
}
35+
36+
public static ResultResponse of(ErrorCode errorCode) { return new ResultResponse(errorCode, ""); }
2737
}

0 commit comments

Comments
 (0)