-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
backend/src/main/java/com/votogether/exception/BadRequestException.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.votogether.exception; | ||
|
||
public class BadRequestException extends BaseException { | ||
|
||
public BadRequestException(final ExceptionType exceptionType) { | ||
super(exceptionType); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
backend/src/main/java/com/votogether/exception/BaseException.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,14 @@ | ||
package com.votogether.exception; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class BaseException extends RuntimeException { | ||
|
||
private final ExceptionType exceptionType; | ||
|
||
public BaseException(final ExceptionType exceptionType) { | ||
this.exceptionType = exceptionType; | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
backend/src/main/java/com/votogether/exception/ExceptionResponse.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,10 @@ | ||
package com.votogether.exception; | ||
|
||
public record ExceptionResponse(int code, String message) { | ||
|
||
public static ExceptionResponse from(final BaseException e) { | ||
final ExceptionType exceptionType = e.getExceptionType(); | ||
return new ExceptionResponse(exceptionType.getCode(), exceptionType.getMessage()); | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
backend/src/main/java/com/votogether/exception/ExceptionType.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.votogether.exception; | ||
|
||
public interface ExceptionType { | ||
|
||
int getCode(); | ||
|
||
String getMessage(); | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
backend/src/main/java/com/votogether/exception/GlobalExceptionHandler.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,29 @@ | ||
package com.votogether.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
@RestControllerAdvice | ||
public class GlobalExceptionHandler { | ||
|
||
@ExceptionHandler | ||
public ResponseEntity<ExceptionResponse> handleException(final Exception e) { | ||
return ResponseEntity.internalServerError() | ||
.body(new ExceptionResponse(-9999, "알 수 없는 서버 에러가 발생했습니다.")); | ||
} | ||
|
||
@ExceptionHandler | ||
public ResponseEntity<ExceptionResponse> handleBadRequestException(final BadRequestException e) { | ||
return ResponseEntity.badRequest() | ||
.body(ExceptionResponse.from(e)); | ||
} | ||
|
||
@ExceptionHandler | ||
public ResponseEntity<ExceptionResponse> handleNotFoundException(final NotFoundException e) { | ||
return ResponseEntity.status(HttpStatus.NOT_FOUND) | ||
.body(ExceptionResponse.from(e)); | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
backend/src/main/java/com/votogether/exception/NotFoundException.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.votogether.exception; | ||
|
||
public class NotFoundException extends BaseException { | ||
|
||
public NotFoundException(final ExceptionType exceptionType) { | ||
super(exceptionType); | ||
} | ||
|
||
} |