1212
1313import java .io .IOException ;
1414
15- import static com .example .solidconnection .custom .exception .ErrorCode .ACCESS_TOKEN_EXPIRED ;
1615import static com .example .solidconnection .custom .exception .ErrorCode .AUTHENTICATION_FAILED ;
1716
1817@ Component
@@ -25,24 +24,15 @@ public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint {
2524 public void commence (HttpServletRequest request , HttpServletResponse response ,
2625 AuthenticationException authException ) throws IOException {
2726 ErrorResponse errorResponse = new ErrorResponse (AUTHENTICATION_FAILED , authException .getMessage ());
28- response .setStatus (HttpServletResponse .SC_UNAUTHORIZED );
29- response .setContentType ("application/json" );
30- response .setCharacterEncoding ("UTF-8" );
31- response .getWriter ().write (objectMapper .writeValueAsString (errorResponse ));
27+ writeResponse (response , errorResponse );
3228 }
3329
34- public void expiredCommence (HttpServletRequest request , HttpServletResponse response ,
35- AuthenticationException authException ) throws IOException {
36- ErrorResponse errorResponse = new ErrorResponse (new CustomException (ACCESS_TOKEN_EXPIRED ));
37- response .setStatus (HttpServletResponse .SC_UNAUTHORIZED );
38- response .setContentType ("application/json" );
39- response .setCharacterEncoding ("UTF-8" );
40- response .getWriter ().write (objectMapper .writeValueAsString (errorResponse ));
30+ public void customCommence (HttpServletResponse response , CustomException customException ) throws IOException {
31+ ErrorResponse errorResponse = new ErrorResponse (customException );
32+ writeResponse (response , errorResponse );
4133 }
4234
43- public void customCommence (HttpServletRequest request , HttpServletResponse response ,
44- CustomException customException ) throws IOException {
45- ErrorResponse errorResponse = new ErrorResponse (customException );
35+ private void writeResponse (HttpServletResponse response , ErrorResponse errorResponse ) throws IOException {
4636 response .setStatus (HttpServletResponse .SC_UNAUTHORIZED );
4737 response .setContentType ("application/json" );
4838 response .setCharacterEncoding ("UTF-8" );
0 commit comments