Skip to content

Commit

Permalink
Merge pull request #113 from UMC-ON/fix/user
Browse files Browse the repository at this point in the history
fix: Exception handler 수정
  • Loading branch information
sanggae4133 authored Nov 30, 2024
2 parents ed44a52 + 079dc1f commit 93ddc35
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.on.server.global.common.exceptions.UnauthorizedException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authorization.AuthorizationDeniedException;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RestControllerAdvice;
Expand Down Expand Up @@ -144,6 +145,21 @@ public ResponseEntity<ErrorResponseDto> handleAuthorizationDeniedException(Autho
);
}

@ExceptionHandler(value = {BadCredentialsException.class})
@ResponseStatus(HttpStatus.UNAUTHORIZED)
public ResponseEntity<ErrorResponseDto> handleBadCredentialsException(BadCredentialsException exception) {
GlobalExceptionHandler.log.debug("[Error message]", exception);
return ResponseEntity
.status(
ResponseCode.INVALID_SIGNIN.getResponseType().getResponseCode()
)
.body(
ErrorResponseDto.of(
ResponseCode.INVALID_SIGNIN
)
);
}

@ExceptionHandler(value = {Exception.class})
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ResponseEntity<ErrorResponseDto> unknownException(Exception exception) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/on/server/global/common/ResponseType.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
public enum ResponseType {

SUCCESS(100),
BAD_REQUEST(401),
UNAUTHORIZED(403),
BAD_REQUEST(400),
UNAUTHORIZED(401),
INTERNAL_SERVER_ERROR(500),
SERVICE_UNAVAILABLE(503);

Expand Down

0 comments on commit 93ddc35

Please sign in to comment.