-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #761 from woowacourse-teams/521/feat-be-error-code
에러 코드 구현 및 적용
- Loading branch information
Showing
35 changed files
with
176 additions
and
107 deletions.
There are no files selected for viewing
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
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
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
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
15 changes: 11 additions & 4 deletions
15
backend/src/main/java/codezap/global/exception/CodeZapException.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 |
---|---|---|
@@ -1,16 +1,23 @@ | ||
package codezap.global.exception; | ||
|
||
import org.springframework.http.HttpStatusCode; | ||
import org.springframework.http.ProblemDetail; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class CodeZapException extends RuntimeException { | ||
|
||
private final HttpStatusCode httpStatusCode; | ||
private final ErrorCode errorCode; | ||
|
||
public CodeZapException(HttpStatusCode httpStatusCode, String message) { | ||
public CodeZapException(ErrorCode errorCode, String message) { | ||
super(message); | ||
this.httpStatusCode = httpStatusCode; | ||
this.errorCode = errorCode; | ||
} | ||
|
||
public ProblemDetail toProblemDetail() { | ||
ProblemDetail problemDetail = ProblemDetail.forStatusAndDetail( | ||
errorCode.getHttpStatus(), | ||
getMessage()); | ||
return GlobalExceptionHandler.setProperties(problemDetail, errorCode.getCode()); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
backend/src/main/java/codezap/global/exception/ErrorCode.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,31 @@ | ||
package codezap.global.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum ErrorCode { | ||
|
||
SPRING_GLOBAL_EXCEPTION(1000, HttpStatus.BAD_REQUEST), | ||
|
||
INVALID_REQUEST(1101, HttpStatus.BAD_REQUEST), | ||
CATEGORY_HAS_TEMPLATES(1102, HttpStatus.BAD_REQUEST), | ||
DEFAULT_CATEGORY(1103, HttpStatus.BAD_REQUEST), | ||
|
||
RESOURCE_NOT_FOUND(1201, HttpStatus.NOT_FOUND), | ||
DUPLICATE_ID(1202, HttpStatus.CONFLICT), | ||
DUPLICATE_CATEGORY(1203, HttpStatus.CONFLICT), | ||
|
||
UNAUTHORIZED_USER(1301, HttpStatus.UNAUTHORIZED), | ||
UNAUTHORIZED_ID(1302, HttpStatus.UNAUTHORIZED), | ||
UNAUTHORIZED_PASSWORD(1303, HttpStatus.UNAUTHORIZED), | ||
FORBIDDEN_ACCESS(1304, HttpStatus.FORBIDDEN), | ||
|
||
INTERNAL_SERVER_ERROR(2000, HttpStatus.INTERNAL_SERVER_ERROR); | ||
|
||
private final int code; | ||
private final HttpStatus httpStatus; | ||
} |
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.