-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[#34] ExceptionHandler 추가하고 Custom Exception으로 변환
- Loading branch information
Showing
17 changed files
with
272 additions
and
19 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
src/main/java/com/dnd/dndtravel/auth/exception/AppleTokenDecodingException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.dnd.dndtravel.auth.exception; | ||
|
||
public class AppleTokenDecodingException extends RuntimeException { | ||
private static final String MESSAGE = "Apple 토큰 payload 해독실패"; | ||
|
||
public AppleTokenDecodingException(Exception e) { | ||
super(MESSAGE, e); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/dnd/dndtravel/auth/exception/JwtTokenDecodingException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.dnd.dndtravel.auth.exception; | ||
|
||
import io.jsonwebtoken.JwtException; | ||
|
||
public class JwtTokenDecodingException extends RuntimeException { | ||
private static final String MESSAGE = "Jwt 토큰 해독 실패"; | ||
|
||
public JwtTokenDecodingException(JwtException e) { | ||
super(MESSAGE, e); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/dnd/dndtravel/auth/exception/JwtTokenExpiredException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.dnd.dndtravel.auth.exception; | ||
|
||
import io.jsonwebtoken.ExpiredJwtException; | ||
|
||
public class JwtTokenExpiredException extends RuntimeException { | ||
private static final String MESSAGE = "Jwt 토큰이 만료되었음"; | ||
|
||
public JwtTokenExpiredException(ExpiredJwtException e) { | ||
super(MESSAGE, e); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/dnd/dndtravel/auth/exception/RefreshTokenInvalidException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.dnd.dndtravel.auth.exception; | ||
|
||
public class RefreshTokenInvalidException extends RuntimeException { | ||
private static final String MESSAGE = "유효하지 않은 RefreshToken 토큰 [refreshToken=%s]"; | ||
|
||
public RefreshTokenInvalidException(String refreshToken) { | ||
super(String.format(MESSAGE, refreshToken)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
src/main/java/com/dnd/dndtravel/common/CommonExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package com.dnd.dndtravel.common; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.MethodArgumentNotValidException; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
import com.dnd.dndtravel.auth.exception.AppleTokenDecodingException; | ||
import com.dnd.dndtravel.auth.exception.JwtTokenDecodingException; | ||
import com.dnd.dndtravel.auth.exception.JwtTokenExpiredException; | ||
import com.dnd.dndtravel.auth.exception.RefreshTokenInvalidException; | ||
import com.dnd.dndtravel.map.exception.MemberAttractionNotFoundException; | ||
import com.dnd.dndtravel.map.exception.MemberNotFoundException; | ||
import com.dnd.dndtravel.map.exception.PhotoDeleteFailException; | ||
import com.dnd.dndtravel.map.exception.PhotoEmptyException; | ||
import com.dnd.dndtravel.map.exception.PhotoInvalidException; | ||
import com.dnd.dndtravel.map.exception.PhotoUploadFailException; | ||
import com.dnd.dndtravel.map.exception.RegionNotFoundException; | ||
//todo 예외클래스가 많아지면 해당클래스가 길어질것으로 예상, 개선필요해보이고 보안 때문에 상태코드별로 애매하게 동일한 메시지를 전달해주고, 스웨거 문서로 상세 오류를 전달해주는데 이 구조가 적절한건지 고민해봐야한다. | ||
@RestControllerAdvice | ||
public class CommonExceptionHandler { | ||
|
||
private static final String INTERNAL_SERVER_ERROR_MESSAGE = "Internal Server Error"; | ||
private static final String BAD_REQUEST_MESSAGE = "잘못된 요청입니다"; | ||
|
||
@ExceptionHandler(MethodArgumentNotValidException.class) | ||
public ResponseEntity<String> runtimeException() { | ||
return ResponseEntity | ||
.status(HttpStatus.BAD_REQUEST) | ||
.body(BAD_REQUEST_MESSAGE); | ||
} | ||
|
||
@ExceptionHandler(MemberNotFoundException.class) | ||
public ResponseEntity<String> runtimeException(MemberNotFoundException e) { | ||
return ResponseEntity | ||
.status(HttpStatus.BAD_REQUEST) | ||
.body(BAD_REQUEST_MESSAGE); | ||
} | ||
|
||
@ExceptionHandler(MemberAttractionNotFoundException.class) | ||
public ResponseEntity<String> runtimeException(MemberAttractionNotFoundException e) { | ||
return ResponseEntity | ||
.status(HttpStatus.BAD_REQUEST) | ||
.body(BAD_REQUEST_MESSAGE); | ||
} | ||
|
||
@ExceptionHandler(RegionNotFoundException.class) | ||
public ResponseEntity<String> runtimeException(RegionNotFoundException e) { | ||
return ResponseEntity | ||
.status(HttpStatus.BAD_REQUEST) | ||
.body(BAD_REQUEST_MESSAGE); | ||
} | ||
|
||
@ExceptionHandler(AppleTokenDecodingException.class) | ||
public ResponseEntity<String> runtimeException(AppleTokenDecodingException e) { | ||
return ResponseEntity | ||
.status(HttpStatus.UNAUTHORIZED) | ||
.body("토큰 인증에 실패했습니다"); | ||
} | ||
|
||
@ExceptionHandler(JwtTokenExpiredException.class) | ||
public ResponseEntity<String> runtimeException(JwtTokenExpiredException e) { | ||
return ResponseEntity | ||
.status(HttpStatus.UNAUTHORIZED) | ||
.body("토큰 인증에 실패했습니다"); | ||
} | ||
|
||
@ExceptionHandler(JwtTokenDecodingException.class) | ||
public ResponseEntity<String> runtimeException(JwtTokenDecodingException e) { | ||
return ResponseEntity | ||
.status(HttpStatus.UNAUTHORIZED) | ||
.body("토큰 인증에 실패했습니다"); | ||
} | ||
|
||
@ExceptionHandler(RefreshTokenInvalidException.class) | ||
public ResponseEntity<String> runtimeException(RefreshTokenInvalidException e) { | ||
return ResponseEntity | ||
.status(HttpStatus.BAD_REQUEST) | ||
.body(BAD_REQUEST_MESSAGE); | ||
} | ||
|
||
@ExceptionHandler(PhotoEmptyException.class) | ||
public ResponseEntity<String> runtimeException(PhotoEmptyException e) { | ||
return ResponseEntity | ||
.status(HttpStatus.BAD_REQUEST) | ||
.body(BAD_REQUEST_MESSAGE); | ||
} | ||
|
||
@ExceptionHandler(PhotoDeleteFailException.class) | ||
public ResponseEntity<String> runtimeException(PhotoDeleteFailException e) { | ||
return ResponseEntity | ||
.status(HttpStatus.INTERNAL_SERVER_ERROR) | ||
.body(INTERNAL_SERVER_ERROR_MESSAGE); | ||
} | ||
|
||
@ExceptionHandler(PhotoUploadFailException.class) | ||
public ResponseEntity<String> runtimeException(PhotoUploadFailException e) { | ||
return ResponseEntity | ||
.status(HttpStatus.INTERNAL_SERVER_ERROR) | ||
.body(INTERNAL_SERVER_ERROR_MESSAGE); | ||
} | ||
|
||
@ExceptionHandler(PhotoInvalidException.class) | ||
public ResponseEntity<String> runtimeException(PhotoInvalidException e) { | ||
return ResponseEntity | ||
.status(HttpStatus.BAD_REQUEST) | ||
.body(BAD_REQUEST_MESSAGE); | ||
} | ||
|
||
|
||
@ExceptionHandler(RuntimeException.class) | ||
public ResponseEntity<String> runtimeException(RuntimeException e) { | ||
return ResponseEntity | ||
.status(HttpStatus.INTERNAL_SERVER_ERROR) | ||
.body(INTERNAL_SERVER_ERROR_MESSAGE); | ||
} | ||
|
||
@ExceptionHandler(Exception.class) | ||
public ResponseEntity<String> runtimeException(Exception e) { | ||
return ResponseEntity | ||
.status(HttpStatus.INTERNAL_SERVER_ERROR) | ||
.body(INTERNAL_SERVER_ERROR_MESSAGE); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/dnd/dndtravel/map/exception/MemberAttractionNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.dnd.dndtravel.map.exception; | ||
|
||
public class MemberAttractionNotFoundException extends RuntimeException { | ||
private static final String MESSAGE = "존재하지 않는 방문기록 [memberAttractionId=%s]"; | ||
|
||
public MemberAttractionNotFoundException(long memberAttractionId) { | ||
super(String.format(MESSAGE, memberAttractionId)); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/dnd/dndtravel/map/exception/MemberNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.dnd.dndtravel.map.exception; | ||
|
||
public class MemberNotFoundException extends RuntimeException { | ||
private static final String MESSAGE = "존재하지 않는 유저 [memberId=%s]"; | ||
|
||
public MemberNotFoundException(long memberId) { | ||
super(String.format(MESSAGE, memberId)); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/dnd/dndtravel/map/exception/PhotoDeleteFailException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.dnd.dndtravel.map.exception; | ||
|
||
import com.amazonaws.SdkClientException; | ||
|
||
public class PhotoDeleteFailException extends RuntimeException{ | ||
private static final String MESSAGE = "s3 이미지 삭제 실패 [imagePath=%s]"; | ||
|
||
public PhotoDeleteFailException(String existingFileName, SdkClientException e) { | ||
super(String.format(MESSAGE,existingFileName), e); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/dnd/dndtravel/map/exception/PhotoEmptyException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.dnd.dndtravel.map.exception; | ||
|
||
public class PhotoEmptyException extends RuntimeException{ | ||
private static final String MESSAGE = "이미지가 존재하지 않음"; | ||
|
||
public PhotoEmptyException() { | ||
super(MESSAGE); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/dnd/dndtravel/map/exception/PhotoInvalidException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.dnd.dndtravel.map.exception; | ||
|
||
public class PhotoInvalidException extends RuntimeException { | ||
|
||
public PhotoInvalidException(String message) { | ||
super(message); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/dnd/dndtravel/map/exception/PhotoUploadFailException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.dnd.dndtravel.map.exception; | ||
|
||
import java.io.IOException; | ||
|
||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import com.amazonaws.SdkClientException; | ||
|
||
public class PhotoUploadFailException extends RuntimeException { | ||
private static final String MESSAGE = "s3 이미지 업로드 실패 [image=%s]"; | ||
|
||
public PhotoUploadFailException(MultipartFile image, IOException e) { | ||
super(String.format(MESSAGE, image), e); | ||
} | ||
|
||
public PhotoUploadFailException(String image, SdkClientException e) { | ||
super(String.format(MESSAGE, image), e); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/dnd/dndtravel/map/exception/RegionNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.dnd.dndtravel.map.exception; | ||
|
||
public class RegionNotFoundException extends RuntimeException { | ||
private static final String MESSAGE = "존재하지 않는 지역 [region=%s]"; | ||
|
||
public RegionNotFoundException(String region) { | ||
super(String.format(MESSAGE, region)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.