-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 fix: JwtExceptionFilter 응답 간소화, ResponseUtil 수정
- Loading branch information
1 parent
6a1a150
commit 6f83bc0
Showing
8 changed files
with
97 additions
and
140 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
55 changes: 22 additions & 33 deletions
55
src/main/java/com/sponus/sponusbe/auth/jwt/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
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
35 changes: 35 additions & 0 deletions
35
src/main/java/com/sponus/sponusbe/auth/jwt/util/HttpResponseUtil.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,35 @@ | ||
package com.sponus.sponusbe.auth.jwt.util; | ||
|
||
import java.io.IOException; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.sponus.sponusbe.global.common.ApiResponse; | ||
|
||
import jakarta.servlet.http.HttpServletResponse; | ||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class HttpResponseUtil { | ||
private static final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
public static void setSuccessResponse(HttpServletResponse response, HttpStatus httpStatus, Object body) | ||
throws IOException { | ||
String responseBody = objectMapper.writeValueAsString(ApiResponse.onSuccess(body)); | ||
response.setContentType(MediaType.APPLICATION_JSON_VALUE); | ||
response.setStatus(httpStatus.value()); | ||
response.setCharacterEncoding("UTF-8"); | ||
response.getWriter().write(responseBody); | ||
} | ||
|
||
public static void setErrorResponse(HttpServletResponse response, HttpStatus httpStatus, Object body) | ||
throws IOException { | ||
response.setContentType(MediaType.APPLICATION_JSON_VALUE); | ||
response.setStatus(httpStatus.value()); | ||
response.setCharacterEncoding("UTF-8"); | ||
objectMapper.writeValue(response.getOutputStream(), body); | ||
} | ||
} |
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.