Skip to content

Commit

Permalink
#33 [Update] 예외처리
Browse files Browse the repository at this point in the history
jwt 토큰 예외처리 추가
  • Loading branch information
Anna-Jin committed Jul 18, 2022
1 parent 708bc97 commit 9b5d97c
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.mpnp.baechelin.exception;

import io.jsonwebtoken.ExpiredJwtException;
import io.jsonwebtoken.MalformedJwtException;
import io.jsonwebtoken.UnsupportedJwtException;
import io.jsonwebtoken.security.SignatureException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
Expand All @@ -14,4 +18,28 @@ protected ResponseEntity<ErrorResponse> handleCustomException(CustomException e)
log.error("handleCustomException throw CustomException : {}", e.getErrorCode());
return ErrorResponse.toResponseEntity(e.getErrorCode());
}

@ExceptionHandler(value = SignatureException.class)
protected ResponseEntity<ErrorResponse> handleSignatureException(SignatureException e) {
log.error("잘못된 JWT 서명입니다.");
return ErrorResponse.toResponseEntity(ErrorCode.WRONG_TYPE_SIGNATURE);
}

@ExceptionHandler(value = MalformedJwtException.class)
protected ResponseEntity<ErrorResponse> handleMalformedJwtException(MalformedJwtException e) {
log.error("유효하지 않은 구성의 JWT 토큰입니다.");
return ErrorResponse.toResponseEntity(ErrorCode.WRONG_TYPE_TOKEN);
}

@ExceptionHandler(value = ExpiredJwtException.class)
protected ResponseEntity<ErrorResponse> handleExpiredJwtException(ExpiredJwtException e) {
log.error("만료된 JWT 토큰입니다.");
return ErrorResponse.toResponseEntity(ErrorCode.EXPIRED_TOKEN);
}

@ExceptionHandler(value = UnsupportedJwtException.class)
protected ResponseEntity<ErrorResponse> handleUnsupportedJwtException(UnsupportedJwtException e) {
log.error("지원되지 않는 형식이나 구성의 JWT 토큰입니다.");
return ErrorResponse.toResponseEntity(ErrorCode.WRONG_TYPE_TOKEN);
}
}

0 comments on commit 9b5d97c

Please sign in to comment.