-
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.
Merge pull request #85 from Map-Pin/issue/81
Issue/81
- Loading branch information
Showing
68 changed files
with
1,712 additions
and
1,185 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
48 changes: 48 additions & 0 deletions
48
src/main/java/com/server/mappin/auth/filter/JwtExceptionFilter.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,48 @@ | ||
package com.server.mappin.auth.filter; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.server.mappin.common.ErrorReasonDto; | ||
import com.server.mappin.common.status.ErrorStatus; | ||
import com.server.mappin.exception.handler.JwtHandler; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.filter.OncePerRequestFilter; | ||
|
||
import javax.servlet.FilterChain; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class JwtExceptionFilter extends OncePerRequestFilter { | ||
|
||
@Override | ||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) | ||
throws ServletException, IOException{ | ||
try{ | ||
filterChain.doFilter(request,response); | ||
}catch (JwtHandler handler){ | ||
|
||
response.setContentType("application/json; charset=UTF-8"); | ||
|
||
String errorName = handler.getMessage(); | ||
ErrorStatus errorStatus = ErrorStatus.valueOf(errorName); | ||
|
||
ErrorReasonDto errorReasonDto = ErrorReasonDto.builder() | ||
.httpStatus(errorStatus.getHttpStatus()) | ||
.code(errorStatus.getCode()) | ||
.message(errorStatus.getMessage()) | ||
.success(false) | ||
.build(); | ||
|
||
ObjectMapper objectMapper = new ObjectMapper(); | ||
String json = objectMapper.writeValueAsString(errorReasonDto); | ||
response.getWriter().write(json); | ||
response.getWriter().flush(); | ||
response.getWriter().close(); | ||
} | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.server.mappin.common; | ||
|
||
|
||
public interface BaseErrorCode { | ||
ErrorReasonDto getReason(); | ||
|
||
ErrorReasonDto getReasonHttpStatus(); | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/server/mappin/common/BaseResponseDto.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,33 @@ | ||
package com.server.mappin.common; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
import com.server.mappin.common.status.SuccessStatus; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@JsonPropertyOrder({"success", "code", "message", "result"}) | ||
@Schema(description = "기본 응답") | ||
public class BaseResponseDto<T> { | ||
private final boolean success; | ||
private final String code; | ||
private final String message; | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
private T result; | ||
|
||
// 성공한 경우 응답 생성 | ||
public static <T> BaseResponseDto<T> onSuccess(T data){ | ||
return new BaseResponseDto<>(true, SuccessStatus._OK.getCode(), SuccessStatus._OK.getMessage(), data); | ||
} | ||
public static <T> BaseResponseDto<T> of(String message, String code, T data){ | ||
return new BaseResponseDto<>(true, code, message, data); | ||
} | ||
|
||
// 실패한 경우 응답 생성 | ||
public static <T> BaseResponseDto<T> onFailure(String message, String code, T data) { | ||
return new BaseResponseDto<>(false, code, message, data); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/server/mappin/common/ErrorReasonDto.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,15 @@ | ||
package com.server.mappin.common; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@Getter | ||
@Builder | ||
public class ErrorReasonDto { | ||
private final HttpStatus httpStatus; | ||
private final boolean success; | ||
private final String code; | ||
private final String message; | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
src/main/java/com/server/mappin/common/status/ErrorStatus.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,67 @@ | ||
package com.server.mappin.common.status; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.server.mappin.common.BaseErrorCode; | ||
import com.server.mappin.common.ErrorReasonDto; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
|
||
|
||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum ErrorStatus implements BaseErrorCode { | ||
//일반적인 응답 | ||
_INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "COMMON500", "서버 에러, 관리자에게 문의 바랍니다."), | ||
_BAD_REQUEST(HttpStatus.BAD_REQUEST,"COMMON400","잘못된 요청입니다."), | ||
_UNAUTHORIZED(HttpStatus.UNAUTHORIZED,"COMMON401","인증이 필요합니다."), | ||
_FORBIDDEN(HttpStatus.FORBIDDEN, "COMMON403", "금지된 요청입니다."), | ||
// 멤버 관려 에러 | ||
MEMBER_NOT_FOUND(HttpStatus.BAD_REQUEST, "MEMBER4001", "사용자가 없습니다."), | ||
NICKNAME_NOT_EXIST(HttpStatus.BAD_REQUEST, "MEMBER4002", "닉네임은 필수 입니다."), | ||
|
||
// 예시,,, | ||
ARTICLE_NOT_FOUND(HttpStatus.NOT_FOUND, "ARTICLE4001", "게시글이 없습니다."), | ||
|
||
// MapService Error | ||
MAP_DONG_NOT_FOUND(HttpStatus.NOT_FOUND, "DONG4001", "동이 존재하지 않습니다"), | ||
MAP_NO_DOCUMENT(HttpStatus.NOT_FOUND, "MAP4001", "문서가 존재하지 않습니다"), | ||
|
||
// S3Service ERRor | ||
S3_NOT_CONVERTABLE(HttpStatus.NOT_MODIFIED, "S33004", "변환이 안됩니다"), | ||
S3_UPLOAD_FAILED(HttpStatus.FORBIDDEN, "S34003", "S3 업로드에 실패하셨습니다"), | ||
S3_WRONG_PATH(HttpStatus.BAD_REQUEST, "S34000", "S3 요청 Path가 잘못되었습니다"), | ||
S3_URL_NOT_FOUND(HttpStatus.NOT_FOUND, "S34001", "S3 URL을 가져올 수 없습니다"), | ||
S3_DELETE_FAILED(HttpStatus.FORBIDDEN, "S34003", "S3 삭제에 실패하셨습니다"), | ||
TEMP_EXCEPTION(HttpStatus.BAD_REQUEST, "TEMP4001", "테스트"), | ||
//JWT 토큰 관련 에러 | ||
JWT_BAD_REQUEST(HttpStatus.BAD_REQUEST,"TOKEN400","잘못된 JWT 서명입니다."), | ||
JWT_TOKEN_NOT_FOUND(HttpStatus.UNAUTHORIZED, "TOKEN401","유효한 JWT 토큰이 없습니다"), | ||
JWT_ACCESS_TOKEN_EXPIRED(HttpStatus.UNAUTHORIZED,"TOKEN402","액세스 토큰이 만료되었습니다"), | ||
JWT_TOKEN_UNSUPPORTED(HttpStatus.UNAUTHORIZED,"TOKEN403","지원하지 않는 JWT 토큰입니다"); | ||
|
||
private final HttpStatus httpStatus; | ||
private final String code; | ||
private final String message; | ||
|
||
@Override | ||
public ErrorReasonDto getReason(){ | ||
return ErrorReasonDto.builder() | ||
.message(message) | ||
.code(code) | ||
.success(false) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public ErrorReasonDto getReasonHttpStatus(){ | ||
return ErrorReasonDto.builder() | ||
.httpStatus(httpStatus) | ||
.message(message) | ||
.code(code) | ||
.success(false) | ||
.build(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/server/mappin/common/status/SuccessStatus.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,16 @@ | ||
package com.server.mappin.common.status; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum SuccessStatus { | ||
_OK(HttpStatus.OK,"COMMON200","성공입니다"); | ||
|
||
private final HttpStatus httpStatus; | ||
private final String code; | ||
private final String message; | ||
|
||
} |
Oops, something went wrong.