Skip to content

Commit

Permalink
Merge pull request #195 from 1223v/login
Browse files Browse the repository at this point in the history
Fix: auth 인증 방식 에러 응답 코드 200 으로 수정
  • Loading branch information
1223v authored Mar 8, 2024
2 parents 0f54baf + f869d4e commit 7a841e8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 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,8 @@ 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()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public UserAuthRes getUserAuthByCustomUserDetails(CustomUserDetails userDetails)

private void verifyUserDetails(CustomUserDetails userDetails) {
if (userDetails == null) {
throw new BusinessLogicException(ExceptionCode.USER_NOT_FOUND);
throw new BusinessLogicException(ExceptionCode.AUTH_ERROR);
}
}

Expand Down

0 comments on commit 7a841e8

Please sign in to comment.