From c4091d14a34966c9163438b7707e53989160453f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=9A=A9=EC=88=98?= Date: Thu, 19 Sep 2024 17:57:44 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Refactor:=20Error=20=EC=9D=91=EB=8B=B5=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/handler/CustomAuthenticationDeniedHandler.java | 4 ---- .../auth/handler/CustomAuthenticationEntryPoint.java | 7 ------- .../worlabel/global/filter/JwtAuthenticationFilter.java | 1 - 3 files changed, 12 deletions(-) diff --git a/backend/src/main/java/com/worlabel/domain/auth/handler/CustomAuthenticationDeniedHandler.java b/backend/src/main/java/com/worlabel/domain/auth/handler/CustomAuthenticationDeniedHandler.java index c07673c..1cecf0e 100644 --- a/backend/src/main/java/com/worlabel/domain/auth/handler/CustomAuthenticationDeniedHandler.java +++ b/backend/src/main/java/com/worlabel/domain/auth/handler/CustomAuthenticationDeniedHandler.java @@ -21,9 +21,5 @@ public class CustomAuthenticationDeniedHandler implements AccessDeniedHandler { public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException { log.debug("오류 : {}", request.getAttribute("error-message")); response.setStatus(HttpServletResponse.SC_FORBIDDEN); - CustomException exception = new CustomException(ErrorCode.ACCESS_DENIED); - ErrorResponse errorResponse = new ErrorResponse(exception, request.getAttribute("error-message").toString()); - response.setContentType("application/json;charset=utf-8"); - response.getWriter().write(errorResponse.toJson()); } } diff --git a/backend/src/main/java/com/worlabel/domain/auth/handler/CustomAuthenticationEntryPoint.java b/backend/src/main/java/com/worlabel/domain/auth/handler/CustomAuthenticationEntryPoint.java index 4c21a6a..e5391ba 100644 --- a/backend/src/main/java/com/worlabel/domain/auth/handler/CustomAuthenticationEntryPoint.java +++ b/backend/src/main/java/com/worlabel/domain/auth/handler/CustomAuthenticationEntryPoint.java @@ -21,12 +21,5 @@ public class CustomAuthenticationEntryPoint implements AuthenticationEntryPoint public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { log.debug("인증 실패 오류 : {} ", request.getAttribute("error-message")); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); - CustomException exception = new CustomException(ErrorCode.INVALID_TOKEN); - if (request.getAttribute("error-message") == null) { - request.setAttribute("error-message", exception.getMessage()); - } - ErrorResponse errorResponse = new ErrorResponse(exception, request.getAttribute("error-message").toString()); - response.setContentType("application/json;charset=UTF-8"); - response.getWriter().write(errorResponse.toJson()); } } diff --git a/backend/src/main/java/com/worlabel/global/filter/JwtAuthenticationFilter.java b/backend/src/main/java/com/worlabel/global/filter/JwtAuthenticationFilter.java index 328c5d3..39b4683 100644 --- a/backend/src/main/java/com/worlabel/global/filter/JwtAuthenticationFilter.java +++ b/backend/src/main/java/com/worlabel/global/filter/JwtAuthenticationFilter.java @@ -49,7 +49,6 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter { throw new JwtException("유효한 JWT 토큰이 없습니다."); } } catch (Exception e) { - log.debug("message: {}", e.getMessage()); request.setAttribute("error-message", e.getMessage()); } filterChain.doFilter(request, response); From 089a57ae94238b8cb0c6257cf91fc067435e3e9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=9A=A9=EC=88=98?= Date: Thu, 19 Sep 2024 18:01:09 +0900 Subject: [PATCH 2/2] =?UTF-8?q?Refactor:=20SuccessResponse=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CustomAuthenticationDeniedHandler.java | 3 -- .../CustomAuthenticationEntryPoint.java | 3 -- .../controller/WorkspaceController.java | 2 - .../global/advice/CustomControllerAdvice.java | 3 -- .../global/response/ErrorResponse.java | 2 - .../global/response/SuccessResponse.java | 53 ------------------- 6 files changed, 66 deletions(-) delete mode 100644 backend/src/main/java/com/worlabel/global/response/SuccessResponse.java diff --git a/backend/src/main/java/com/worlabel/domain/auth/handler/CustomAuthenticationDeniedHandler.java b/backend/src/main/java/com/worlabel/domain/auth/handler/CustomAuthenticationDeniedHandler.java index 1cecf0e..c1eb8e7 100644 --- a/backend/src/main/java/com/worlabel/domain/auth/handler/CustomAuthenticationDeniedHandler.java +++ b/backend/src/main/java/com/worlabel/domain/auth/handler/CustomAuthenticationDeniedHandler.java @@ -1,8 +1,5 @@ package com.worlabel.domain.auth.handler; -import com.worlabel.global.exception.CustomException; -import com.worlabel.global.exception.ErrorCode; -import com.worlabel.global.response.ErrorResponse; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; diff --git a/backend/src/main/java/com/worlabel/domain/auth/handler/CustomAuthenticationEntryPoint.java b/backend/src/main/java/com/worlabel/domain/auth/handler/CustomAuthenticationEntryPoint.java index e5391ba..773a041 100644 --- a/backend/src/main/java/com/worlabel/domain/auth/handler/CustomAuthenticationEntryPoint.java +++ b/backend/src/main/java/com/worlabel/domain/auth/handler/CustomAuthenticationEntryPoint.java @@ -1,8 +1,5 @@ package com.worlabel.domain.auth.handler; -import com.worlabel.global.exception.CustomException; -import com.worlabel.global.exception.ErrorCode; -import com.worlabel.global.response.ErrorResponse; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; diff --git a/backend/src/main/java/com/worlabel/domain/workspace/controller/WorkspaceController.java b/backend/src/main/java/com/worlabel/domain/workspace/controller/WorkspaceController.java index d17ff23..e832f4b 100644 --- a/backend/src/main/java/com/worlabel/domain/workspace/controller/WorkspaceController.java +++ b/backend/src/main/java/com/worlabel/domain/workspace/controller/WorkspaceController.java @@ -12,8 +12,6 @@ import com.worlabel.global.annotation.CurrentUser; import com.worlabel.global.config.swagger.SwaggerApiError; import com.worlabel.global.config.swagger.SwaggerApiSuccess; import com.worlabel.global.exception.ErrorCode; -import com.worlabel.global.response.BaseResponse; -import com.worlabel.global.response.SuccessResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; diff --git a/backend/src/main/java/com/worlabel/global/advice/CustomControllerAdvice.java b/backend/src/main/java/com/worlabel/global/advice/CustomControllerAdvice.java index 673c590..f2b3873 100644 --- a/backend/src/main/java/com/worlabel/global/advice/CustomControllerAdvice.java +++ b/backend/src/main/java/com/worlabel/global/advice/CustomControllerAdvice.java @@ -2,8 +2,6 @@ package com.worlabel.global.advice; import com.amazonaws.Response; import com.worlabel.global.exception.CustomException; -import com.worlabel.global.exception.ErrorCode; -import com.worlabel.global.response.ErrorResponse; import com.worlabel.global.service.NotificationManager; import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; @@ -16,7 +14,6 @@ import org.springframework.web.bind.MissingServletRequestParameterException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestControllerAdvice; -import org.springframework.web.servlet.NoHandlerFoundException; import org.springframework.web.servlet.resource.NoResourceFoundException; import java.lang.reflect.Executable; diff --git a/backend/src/main/java/com/worlabel/global/response/ErrorResponse.java b/backend/src/main/java/com/worlabel/global/response/ErrorResponse.java index 884da53..651f4e5 100644 --- a/backend/src/main/java/com/worlabel/global/response/ErrorResponse.java +++ b/backend/src/main/java/com/worlabel/global/response/ErrorResponse.java @@ -20,8 +20,6 @@ import java.util.stream.Collectors; @Getter public class ErrorResponse extends BaseResponse { - - public ErrorResponse(boolean isSuccess, int status, int code, String message, Errors errors) { super(isSuccess, status, code, message); super.errors = parseErrors(errors); diff --git a/backend/src/main/java/com/worlabel/global/response/SuccessResponse.java b/backend/src/main/java/com/worlabel/global/response/SuccessResponse.java deleted file mode 100644 index c8cdd15..0000000 --- a/backend/src/main/java/com/worlabel/global/response/SuccessResponse.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.worlabel.global.response; - -import org.springframework.http.HttpStatus; - -/** - * 성공시 응답 객체 - * - * @param 응답 데이터 타입 - */ -public class SuccessResponse extends BaseResponse { - /** - * 빈 응답 데이터 - 객체 생성시 보내는 빈 응답 데이터 - */ - private static final SuccessResponse EMPTY = new SuccessResponse<>(); - - /** - * 성공 응답 객체 생성자 - */ - public SuccessResponse() { - super(true, HttpStatus.OK.value(), 200, "success"); - } - - /** - * 성공 응답 객체 - * - * @param data 성공시 반환하는 데이터 - */ - public SuccessResponse(T data) { - super(true, 200, 200, "success"); - super.data = data; - } - - /** - * 빈 응답 리턴 - * - * @return 빈 응답 객체 - */ - public static SuccessResponse empty() { - return EMPTY; - } - - /** - * 데이터를 성공 응답 객체에 감싸서 보내는 메서드 - * - * @param data 응답 할 데이터 - * @param 응답 할 데이터 타입 - * @return 데이터를 감싼 응답 객체 - */ - public static SuccessResponse of(T data) { - return new SuccessResponse(data); - } - -} \ No newline at end of file