Skip to content

Commit

Permalink
feat: Error handling when token value is null
Browse files Browse the repository at this point in the history
  • Loading branch information
jiyeoon00 committed Jul 20, 2023
1 parent bf6a2af commit af7184b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.universe.uni.config.jwt;

import static java.util.Objects.*;

import java.io.IOException;

import javax.servlet.FilterChain;
Expand All @@ -12,6 +14,8 @@
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

import com.universe.uni.exception.UnauthorizedException;
import com.universe.uni.exception.dto.ErrorType;
import com.universe.uni.service.JwtManager;

import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -48,6 +52,10 @@ private String getJwtFromRequest(HttpServletRequest request) {
final String tokenType = "Bearer ";

String header = request.getHeader("Authorization");

if(isNull(header)) {
throw new UnauthorizedException(ErrorType.TOKEN_VALUE_NOT_EXIST);
}
return header.substring(tokenType.length());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public enum ErrorType {
ALREADY_GAME_DONE(HttpStatus.BAD_REQUEST, "UE1005", "이미 종료된 라운드입니다."),
COUPLE_NOT_EXISTENT(HttpStatus.BAD_REQUEST, "UE1006", "존재하지 않는 커플 id 입니다"),
INVALID_INVITE_CODE(HttpStatus.BAD_REQUEST, "UE1007", "올바르지 않은 초대 코드입니다."),
TOKEN_VALUE_NOT_EXIST(HttpStatus.BAD_REQUEST, "UE1008", "토큰 값이 존재하지 않습니다."),

/**
* 401 Unauthorized
Expand Down

0 comments on commit af7184b

Please sign in to comment.