Merge branch 'be/refactor/error' into 'be/develop'

Refactor: ErrorResponse 제거

See merge request s11-s-project/S11P21S002!100
This commit is contained in:
정현조 2024-09-19 19:24:04 +09:00
commit f2cf8f21e4
7 changed files with 0 additions and 78 deletions

View File

@ -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;
@ -21,9 +18,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());
}
}

View File

@ -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;
@ -21,12 +18,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());
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -20,8 +20,6 @@ import java.util.stream.Collectors;
@Getter
public class ErrorResponse extends BaseResponse<CustomError> {
public ErrorResponse(boolean isSuccess, int status, int code, String message, Errors errors) {
super(isSuccess, status, code, message);
super.errors = parseErrors(errors);

View File

@ -1,53 +0,0 @@
package com.worlabel.global.response;
import org.springframework.http.HttpStatus;
/**
* 성공시 응답 객체
*
* @param <T> 응답 데이터 타입
*/
public class SuccessResponse<T> extends BaseResponse<T> {
/**
* 응답 데이터 - 객체 생성시 보내는 응답 데이터
*/
private static final SuccessResponse<Void> 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<Void> empty() {
return EMPTY;
}
/**
* 데이터를 성공 응답 객체에 감싸서 보내는 메서드
*
* @param data 응답 데이터
* @param <T> 응답 데이터 타입
* @return 데이터를 감싼 응답 객체
*/
public static <T> SuccessResponse<T> of(T data) {
return new SuccessResponse<T>(data);
}
}