Skip to content

Commit 33fb5aa

Browse files
committed
[TNT-28] refactor: 변수, 로그 개행 수정
1 parent 2590e9b commit 33fb5aa

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

Diff for: src/main/java/com/tnt/application/auth/SessionService.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ public class SessionService {
2828

2929
public String authenticate(HttpServletRequest request) {
3030
String authHeader = request.getHeader(AUTHORIZATION_HEADER);
31-
String sessionId;
3231

3332
if (isBlank(authHeader) || !authHeader.startsWith(SESSION_ID_PREFIX)) {
3433
log.error("Authorization 헤더가 존재하지 않거나 올바르지 않은 형식입니다.");
34+
3535
throw new UnauthorizedException("인가 세션이 존재하지 않습니다.");
3636
}
37-
sessionId = authHeader.substring(SESSION_ID_PREFIX.length());
37+
38+
String sessionId = authHeader.substring(SESSION_ID_PREFIX.length());
3839

3940
requireNonNull(redisTemplate.opsForValue().get(sessionId), "세션 스토리지에 세션이 존재하지 않습니다.");
4041

Diff for: src/main/java/com/tnt/global/auth/SessionAuthenticationFilter.java

+6
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
3939

4040
log.info("들어온 요청 - URI: {}, Query: {}, Method: {}", requestUri, queryString != null ? queryString : "쿼리 스트링 없음",
4141
request.getMethod());
42+
4243
if (isAllowedUri(requestUri)) {
4344
log.info("{} 허용 URI. 세션 유효성 검사 스킵.", requestUri);
45+
4446
filterChain.doFilter(request, response);
4547
return;
4648
}
@@ -49,6 +51,7 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
4951
checkSessionAndAuthentication(request);
5052
} catch (RuntimeException e) {
5153
log.error("인증 처리 중 에러 발생: ", e);
54+
5255
handleUnauthorizedException(response, e);
5356
return;
5457
}
@@ -65,6 +68,7 @@ private boolean isAllowedUri(String requestUri) {
6568
break;
6669
}
6770
}
71+
6872
log.info("URI {} is {}allowed", requestUri, allowed ? "" : "not ");
6973

7074
return allowed;
@@ -79,6 +83,7 @@ private void checkSessionAndAuthentication(HttpServletRequest request) {
7983
private void handleUnauthorizedException(HttpServletResponse response, RuntimeException exception) throws
8084
IOException {
8185
log.error("인증 실패: ", exception);
86+
8287
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
8388
response.setContentType("application/json;charset=UTF-8");
8489
response.getWriter().write(exception.getMessage());
@@ -95,6 +100,7 @@ private void saveAuthentication(Long sessionId) {
95100
authoritiesMapper.mapAuthorities(userDetails.getAuthorities()));
96101

97102
SecurityContextHolder.getContext().setAuthentication(authentication);
103+
98104
log.info("시큐리티 컨텍스트에 인증 정보 저장 완료 - SessionId: {}", sessionId);
99105
}
100106
}

Diff for: src/main/java/com/tnt/global/error/handler/GlobalExceptionHandler.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public class GlobalExceptionHandler {
3939
@ExceptionHandler(MissingServletRequestParameterException.class)
4040
protected ErrorResponse handleMissingServletRequestParameter(MissingServletRequestParameterException exception) {
4141
String errorMessage = String.format("필수 파라미터 '%s'가 누락되었습니다.", exception.getParameterName());
42+
4243
log.warn("Required request parameter is missing: {}", exception.getParameterName());
4344

4445
return new ErrorResponse(errorMessage);
@@ -48,12 +49,11 @@ protected ErrorResponse handleMissingServletRequestParameter(MissingServletReque
4849
@ResponseStatus(HttpStatus.BAD_REQUEST)
4950
@ExceptionHandler(MethodArgumentTypeMismatchException.class)
5051
protected ErrorResponse handleMethodArgumentTypeMismatch(MethodArgumentTypeMismatchException exception) {
51-
String errorMessage;
52-
log.warn("Type mismatch for parameter: {}. Required type: {}", exception.getName(),
52+
String errorMessage = String.format("파라미터 '%s'의 형식이 올바르지 않습니다. 예상 타입: %s", exception.getName(),
5353
requireNonNull(exception.getRequiredType()).getSimpleName());
5454

55-
errorMessage = String.format("파라미터 '%s'의 형식이 올바르지 않습니다. 예상 타입: %s", exception.getName(),
56-
exception.getRequiredType().getSimpleName());
55+
log.warn("Type mismatch for parameter: {}. Required type: {}", exception.getName(),
56+
requireNonNull(exception.getRequiredType()).getSimpleName());
5757

5858
return new ErrorResponse(errorMessage);
5959
}
@@ -62,15 +62,14 @@ protected ErrorResponse handleMethodArgumentTypeMismatch(MethodArgumentTypeMisma
6262
@ResponseStatus(HttpStatus.BAD_REQUEST)
6363
@ExceptionHandler(ConstraintViolationException.class)
6464
protected ErrorResponse handleConstraintViolationException(ConstraintViolationException exception) {
65-
log.warn("Constraint violation: {}", exception.getMessage());
66-
6765
List<String> errors = exception.getConstraintViolations()
6866
.stream()
6967
.map(violation -> violation.getPropertyPath() + ": " + violation.getMessage())
7068
.toList();
71-
7269
String errorMessage = String.join(", ", errors);
7370

71+
log.warn("Constraint violation: {}", exception.getMessage());
72+
7473
return new ErrorResponse("입력값이 유효하지 않습니다: " + errorMessage);
7574
}
7675

@@ -120,6 +119,7 @@ protected ErrorResponse handleRuntimeException(RuntimeException exception) {
120119

121120
String errorKeyInfo = String.format(ERROR_KEY_FORMAT, sb);
122121
String exceptionTypeInfo = String.format(EXCEPTION_CLASS_TYPE_MESSAGE_FORMANT, exception.getClass());
122+
123123
log.error("{}{}{}", exception.getMessage(), errorKeyInfo, exceptionTypeInfo);
124124

125125
return new ErrorResponse(DEFAULT_ERROR_MESSAGE + errorKeyInfo);

0 commit comments

Comments
 (0)