-
Notifications
You must be signed in to change notification settings - Fork 1
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
[Feature] 공통 응답 포맷 생성, 예외 처리 추가
- Loading branch information
Showing
6 changed files
with
175 additions
and
48 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
36 changes: 36 additions & 0 deletions
36
src/main/java/ewha/lux/once/global/common/CommonResponse.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,36 @@ | ||
package ewha.lux.once.global.common; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@Builder | ||
public class CommonResponse<T> { | ||
|
||
private int code; | ||
private boolean inSuccess; | ||
private String message; | ||
private T result; | ||
|
||
// 요청에 성공한 경우 | ||
@Builder | ||
public CommonResponse(ResponseCode status, T result) { | ||
this.code = status.getCode(); | ||
this.inSuccess = status.isInSuccess(); | ||
this.message = status.getMessage(); | ||
|
||
this.result = result; | ||
} | ||
|
||
// 요청에 실패한 경우 | ||
@Builder | ||
public CommonResponse(ResponseCode status) { | ||
this.code = status.getCode(); | ||
this.inSuccess = status.isInSuccess(); | ||
this.message = status.getMessage(); | ||
} | ||
|
||
} | ||
|
12 changes: 12 additions & 0 deletions
12
src/main/java/ewha/lux/once/global/common/CustomException.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,12 @@ | ||
package ewha.lux.once.global.common; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Getter | ||
public class CustomException extends Exception { | ||
public ResponseCode status; | ||
} |
57 changes: 57 additions & 0 deletions
57
src/main/java/ewha/lux/once/global/common/ResponseCode.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,57 @@ | ||
package ewha.lux.once.global.common; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum ResponseCode { | ||
/* | ||
1000 : Request 성공 | ||
*/ | ||
SUCCESS(1000, true, "요청에 성공하였습니다."), | ||
|
||
|
||
/* | ||
2000~ : Request 오류 | ||
*/ | ||
|
||
|
||
|
||
// ===================================== | ||
/* | ||
3000~ : Response 오류 | ||
*/ | ||
// 3000~ : user 관련 오류 | ||
RESPONSE_ERROR(3000, false, "값을 불러오는데 실패하였습니다."), | ||
INVALID_USER_ID(3001, false, "아이디가 존재하지 않습니다."), | ||
FAILED_TO_LOGIN(3002, false, "비밀번호가 일치하지 않습니다."), | ||
|
||
// 3100~ : | ||
|
||
// 3200~ : | ||
|
||
|
||
// ===================================== | ||
|
||
// 그 외 오류 | ||
INTERNAL_SERVER_ERROR(9000, false, "서버 오류가 발생했습니다."); | ||
|
||
|
||
// ===================================== | ||
private int code; | ||
private boolean inSuccess; | ||
private String message; | ||
|
||
|
||
/* | ||
해당되는 코드 매핑 | ||
@param code | ||
@param inSuccess | ||
@param message | ||
*/ | ||
ResponseCode(int code, boolean inSuccess, String message) { | ||
this.inSuccess = inSuccess; | ||
this.code = code; | ||
this.message = message; | ||
} | ||
} |