File tree Expand file tree Collapse file tree 3 files changed +41
-0
lines changed
src/main/java/com/somemore/global/exception Expand file tree Collapse file tree 3 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,10 @@ public enum ExceptionMessage {
6969 // NOTE
7070 NOT_EXISTS_NOTE ("존재하지 않는 쪽지입니다." ),
7171
72+ // AUTH
73+ AUTHENTICATION_MISSING ("사용자가 인증되지 않았습니다." ),
74+ INVALID_PRINCIPAL_TYPE ("인증 객체 타입이 올바르지 않습니다." ),
75+
7276 ;
7377 private final String message ;
7478}
Original file line number Diff line number Diff line change 1+ package com .somemore .global .exception ;
2+
3+ import org .springframework .security .core .AuthenticationException ;
4+
5+ public class InvalidAuthenticationException extends AuthenticationException {
6+
7+ public InvalidAuthenticationException (final String message ) {
8+ super (message );
9+ }
10+
11+ public InvalidAuthenticationException (final String message , final Throwable cause ) {
12+ super (message , cause );
13+ }
14+
15+ public InvalidAuthenticationException (final ExceptionMessage message ) {
16+ super (message .getMessage ());
17+ }
18+
19+ public InvalidAuthenticationException (final ExceptionMessage message , final Throwable cause ) {
20+ super (message .getMessage (), cause );
21+ }
22+ }
Original file line number Diff line number Diff line change 33import com .somemore .global .exception .BadRequestException ;
44import com .somemore .global .exception .DuplicateException ;
55import com .somemore .global .exception .ImageUploadException ;
6+ import com .somemore .global .exception .InvalidAuthenticationException ;
67import com .somemore .global .exception .NoSuchElementException ;
8+ import lombok .extern .slf4j .Slf4j ;
79import org .springframework .http .HttpStatus ;
810import org .springframework .http .ProblemDetail ;
911import org .springframework .web .bind .MethodArgumentNotValidException ;
1012import org .springframework .web .bind .annotation .ExceptionHandler ;
1113import org .springframework .web .bind .annotation .RestControllerAdvice ;
1214
1315@ RestControllerAdvice
16+ @ Slf4j
1417public class GlobalExceptionHandler {
1518
1619 //예시 코드
@@ -66,4 +69,16 @@ ProblemDetail handleNoSuchElementException(final NoSuchElementException e) {
6669 return problemDetail ;
6770 }
6871
72+ @ ExceptionHandler (InvalidAuthenticationException .class )
73+ ProblemDetail handleInvalidAuthenticationException (InvalidAuthenticationException e ) {
74+
75+ ProblemDetail problemDetail = ProblemDetail .forStatusAndDetail (HttpStatus .BAD_REQUEST , e .getMessage ());
76+ problemDetail .setTitle ("인증 문제" );
77+ problemDetail .setDetail ("인증에 문제가 발생했습니다." );
78+
79+ log .warn ("InvalidAuthenticationException: {}" , e .getMessage ());
80+
81+ return problemDetail ;
82+ }
83+
6984}
You can’t perform that action at this time.
0 commit comments