Skip to content

Commit

Permalink
fix: 응답 상태 수정 (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Haewonny committed Feb 12, 2024
1 parent 216050b commit 27ba166
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;
Expand All @@ -28,11 +29,11 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
try {
chain.doFilter(request, response);
} catch (JwtException | IOException | ServletException ex) {
setErrorResponse(request, response, ex);
setErrorResponse(HttpStatus.UNAUTHORIZED, response, ex);
}
}

public void setErrorResponse(HttpServletRequest req, HttpServletResponse res, Throwable ex) throws IOException {
public void setErrorResponse(HttpStatus status, HttpServletResponse res, Throwable ex) throws IOException {

res.setContentType(MediaType.APPLICATION_JSON_VALUE);
if (ex.getMessage().equals(BaseResponseStatus.INVALID_TOKEN.getMessage())) {
Expand All @@ -50,8 +51,8 @@ public void setErrorResponse(HttpServletRequest req, HttpServletResponse res, Th
body.put("inSuccess", false);
body.put("message", ex.getMessage());
body.put("result", "Unauthorized error");
res.setStatus(status.value());

objectMapper.writeValue(res.getOutputStream(), body);
res.setStatus(HttpServletResponse.SC_OK);
}
}

0 comments on commit 27ba166

Please sign in to comment.