-
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.
# Conflicts: # .github/workflows/manual-prod-deploy.yaml # Dockerfile # application/src/main/resources/appenders/console-appender.xml # application/src/main/resources/application.yaml # infrastructure/src/main/java/org/depromeet/spot/infrastructure/aws/config/ObjectStorageConfig.java # infrastructure/src/main/java/org/depromeet/spot/infrastructure/aws/objectstorage/PresignedUrlGenerator.java # infrastructure/src/main/resources/application-ncp.yaml
- Loading branch information
Showing
29 changed files
with
321 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
13 changes: 13 additions & 0 deletions
13
...ion/src/main/java/org/depromeet/spot/application/common/exception/CustomJwtException.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,13 @@ | ||
package org.depromeet.spot.application.common.exception; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class CustomJwtException extends RuntimeException { | ||
private final JwtErrorCode jwtErrorCode; | ||
|
||
public CustomJwtException(JwtErrorCode jwtErrorCode) { | ||
super(jwtErrorCode.getMessage()); | ||
this.jwtErrorCode = jwtErrorCode; | ||
} | ||
} |
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
54 changes: 54 additions & 0 deletions
54
...src/main/java/org/depromeet/spot/application/common/exception/ExceptionHandlerFilter.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,54 @@ | ||
package org.depromeet.spot.application.common.exception; | ||
|
||
import java.io.IOException; | ||
|
||
import jakarta.servlet.FilterChain; | ||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
|
||
import org.springframework.http.MediaType; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.filter.OncePerRequestFilter; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Component | ||
public class ExceptionHandlerFilter extends OncePerRequestFilter { | ||
|
||
private final String UTF_8 = "UTF-8"; | ||
|
||
@Override | ||
protected void doFilterInternal( | ||
HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) | ||
throws ServletException, IOException { | ||
try { | ||
filterChain.doFilter(request, response); | ||
} catch (CustomJwtException e) { | ||
// logging 안 하면 콘솔에 로그 출력 안 됨. | ||
logger.error("CustomJwtException : {}", e); | ||
setErrorResponse(response, e.getJwtErrorCode()); | ||
} | ||
} | ||
|
||
private void setErrorResponse(HttpServletResponse response, JwtErrorCode jwtErrorCode) | ||
throws IOException { | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
response.setStatus(jwtErrorCode.getStatus().value()); | ||
response.setContentType(MediaType.APPLICATION_JSON_VALUE); | ||
response.setCharacterEncoding(UTF_8); | ||
ErrorResponse errorResponse = | ||
new ErrorResponse(jwtErrorCode.getCode(), jwtErrorCode.getMessage()); | ||
response.getWriter().write(objectMapper.writeValueAsString(errorResponse)); | ||
} | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public static class ErrorResponse { | ||
private final String code; | ||
private final String message; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
application/src/main/java/org/depromeet/spot/application/common/exception/JwtErrorCode.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,20 @@ | ||
package org.depromeet.spot.application.common.exception; | ||
|
||
import org.depromeet.spot.common.exception.ErrorCode; | ||
import org.springframework.http.HttpStatus; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@AllArgsConstructor | ||
@Getter | ||
public enum JwtErrorCode implements ErrorCode { | ||
NONEXISTENT_TOKEN(HttpStatus.UNAUTHORIZED, "JWT001", "해당 요청은 Jwt 토큰이 필요합니다."), | ||
INVALID_TOKEN(HttpStatus.UNAUTHORIZED, "JWT002", "잘못된 토큰입니다."), | ||
EXPIRED_TOKEN(HttpStatus.UNAUTHORIZED, "JWT003", "만료된 토큰입니다."), | ||
INVALID_PERMISSION(HttpStatus.UNAUTHORIZED, "JWT004", "사용자가 권한이 없습니다."); | ||
|
||
private final HttpStatus status; | ||
private final String code; | ||
private final String message; | ||
} |
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
Oops, something went wrong.