Skip to content

Commit

Permalink
Fix: auth 인증 방식 에러 응답 코드 200 으로 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
1223v committed Mar 8, 2024
1 parent 8e2fa8b commit 4d2ffd3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.readyvery.readyverydemo.global.exception;

import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class AuthErrorResponse {
private boolean auth;

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ public enum ExceptionCode {
ORDER_ALREADY_END(400, "Order is already end."),
POINT_NOT_ENOUGH(400, "Point is not enough."),
INVALID_INPUT(400, "Invalid input."),
UNAUTHORIZED(400, "Already User");
UNAUTHORIZED(400, "Already User"),
AUTH_ERROR(403, "Auth Error"),
;

private int status;
private String message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@
@RestControllerAdvice
public class GlobalExceptionAdvice {
@ExceptionHandler(BusinessLogicException.class)
public ResponseEntity<ErrorResponse.Default> handleException(BusinessLogicException exception) {
final ErrorResponse.Default response = ErrorResponse.of(exception.getExceptionCode());
return new ResponseEntity<>(response, HttpStatus.valueOf(response.getStatus()));
public ResponseEntity<?> handleBusinessLogicException(BusinessLogicException exception) {
// AUTH_ERROR 예외 처리
if (exception.getExceptionCode() == ExceptionCode.AUTH_ERROR) {
AuthErrorResponse response = AuthErrorResponse.builder().auth(false).build();
return ResponseEntity.status(HttpStatus.OK).body(response);
}

// 다른 BusinessLogicException 예외 처리
final ErrorResponse.Default defaultResponse = ErrorResponse.of(exception.getExceptionCode());
return new ResponseEntity<>(defaultResponse, HttpStatus.valueOf(defaultResponse.getStatus()));
}
}

0 comments on commit 4d2ffd3

Please sign in to comment.