초기소스
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package com.wb.domainserver.exception;
|
||||
|
||||
import com.wb.domainserver.exception.code.ErrorCode;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
|
||||
public class CustomJwtAuthenticationException extends AuthenticationException {
|
||||
|
||||
public CustomJwtAuthenticationException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public CustomJwtAuthenticationException(ErrorCode errorCode) {
|
||||
super(errorCode.getMessage());
|
||||
}
|
||||
|
||||
|
||||
public CustomJwtAuthenticationException(ErrorCode errCode, Throwable t) {
|
||||
super(errCode.getMessage(), t);
|
||||
}
|
||||
}
|
||||
30
src/main/java/com/wb/domainserver/exception/ErrCode.java
Normal file
30
src/main/java/com/wb/domainserver/exception/ErrCode.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package com.wb.domainserver.exception;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ErrCode {
|
||||
|
||||
//APPLICATION_SERVER_ERROR
|
||||
PAGE_NOT_FOUND(HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND.value(), "페이지를 찾을수 없습니다"),
|
||||
BAD_REQUEST(HttpStatus.BAD_REQUEST, HttpStatus.BAD_REQUEST.value(), "잘못된 요청입니다"),
|
||||
NOT_AUTHENTICATED(HttpStatus.UNAUTHORIZED, HttpStatus.UNAUTHORIZED.value(), "인증이 필요한 요청입니다"),
|
||||
INVALID_PERMISSION(HttpStatus.FORBIDDEN, HttpStatus.FORBIDDEN.value(), "해당 요청에 권한이 없습니다"),
|
||||
METHOD_NOT_ALLOWED(HttpStatus.METHOD_NOT_ALLOWED, HttpStatus.METHOD_NOT_ALLOWED.value(), "허용되지 않는 요청 메소드입니다"),
|
||||
REQUEST_TIMEOUT(HttpStatus.REQUEST_TIMEOUT, HttpStatus.REQUEST_TIMEOUT.value(), "요청 시간이 만료되었습니다."),
|
||||
|
||||
//DATABASE_TRANSACTION_ERROR
|
||||
DUPLICATED_USER_NAME(HttpStatus.CONFLICT, HttpStatus.CONFLICT.value(), "유저명이 중복됩니다"),
|
||||
|
||||
//INTERNAL_SERVER_ERROR,
|
||||
INTERNAL_SEVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, HttpStatus.INTERNAL_SERVER_ERROR.value(), "실행 도중 예기치 못한 오류가 발생하였습니다"),
|
||||
USERNAME_NOT_FOUND(HttpStatus.INTERNAL_SERVER_ERROR, HttpStatus.INTERNAL_SERVER_ERROR.value(), "유저를 찾을 수 없습니다"),
|
||||
DATABASE_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, HttpStatus.INTERNAL_SERVER_ERROR.value(), "Database 에러가 발생하였습니다");
|
||||
|
||||
private HttpStatus status;
|
||||
private int statusCode;
|
||||
private String message;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.wb.domainserver.exception;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class FileStorageException extends RuntimeException {
|
||||
|
||||
public FileStorageException(String message) {
|
||||
super(message);
|
||||
}
|
||||
public FileStorageException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
package com.wb.domainserver.exception;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Controller 내에서 발생하는 Exception 대해서 Catch 하여 응답값(Response)을 보내주는 기능을 수행함.
|
||||
*/
|
||||
@Slf4j
|
||||
//@RestControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
// private final HttpStatus HTTP_STATUS_OK = HttpStatus.OK;
|
||||
//
|
||||
// /**
|
||||
// * [Exception] API 호출 시 '객체' 혹은 '파라미터' 데이터 값이 유효하지 않은 경우
|
||||
// *
|
||||
// * @param ex MethodArgumentNotValidException
|
||||
// * @return ResponseEntity<ErrorResponse>
|
||||
// */
|
||||
// @ExceptionHandler(MethodArgumentNotValidException.class)
|
||||
// protected ResponseEntity<ErrorResponse> handleMethodArgumentNotValidException(MethodArgumentNotValidException ex) {
|
||||
// log.error("handleMethodArgumentNotValidException", ex);
|
||||
// BindingResult bindingResult = ex.getBindingResult();
|
||||
// StringBuilder stringBuilder = new StringBuilder();
|
||||
// for (FieldError fieldError : bindingResult.getFieldErrors()) {
|
||||
// stringBuilder.append(fieldError.getField()).append(":");
|
||||
// stringBuilder.append(fieldError.getDefaultMessage());
|
||||
// stringBuilder.append(", ");
|
||||
// }
|
||||
// final ErrorResponse response = ErrorResponse.of(ErrorCode.NOT_VALID_ERROR, String.valueOf(stringBuilder));
|
||||
// return new ResponseEntity<>(response, HTTP_STATUS_OK);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * [Exception] API 호출 시 'Header' 내에 데이터 값이 유효하지 않은 경우
|
||||
// *
|
||||
// * @param ex MissingRequestHeaderException
|
||||
// * @return ResponseEntity<ErrorResponse>
|
||||
// */
|
||||
// @ExceptionHandler(MissingRequestHeaderException.class)
|
||||
// protected ResponseEntity<ErrorResponse> handleMissingRequestHeaderException(MissingRequestHeaderException ex) {
|
||||
// log.error("MissingRequestHeaderException", ex);
|
||||
// final ErrorResponse response = ErrorResponse.of(ErrorCode.REQUEST_BODY_MISSING_ERROR, ex.getMessage());
|
||||
// return new ResponseEntity<>(response, HTTP_STATUS_OK);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * [Exception] 클라이언트에서 Body로 '객체' 데이터가 넘어오지 않았을 경우
|
||||
// *
|
||||
// * @param ex HttpMessageNotReadableException
|
||||
// * @return ResponseEntity<ErrorResponse>
|
||||
// */
|
||||
// @ExceptionHandler(HttpMessageNotReadableException.class)
|
||||
// protected ResponseEntity<ErrorResponse> handleHttpMessageNotReadableException(
|
||||
// HttpMessageNotReadableException ex) {
|
||||
// log.error("HttpMessageNotReadableException", ex);
|
||||
// final ErrorResponse response = ErrorResponse.of(ErrorCode.REQUEST_BODY_MISSING_ERROR, ex.getMessage());
|
||||
// return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * [Exception] 클라이언트에서 request로 '파라미터로' 데이터가 넘어오지 않았을 경우
|
||||
// *
|
||||
// * @param ex MissingServletRequestParameterException
|
||||
// * @return ResponseEntity<ErrorResponse>
|
||||
// */
|
||||
// @ExceptionHandler(MissingServletRequestParameterException.class)
|
||||
// protected ResponseEntity<ErrorResponse> handleMissingRequestHeaderExceptionException(
|
||||
// MissingServletRequestParameterException ex) {
|
||||
// log.error("handleMissingServletRequestParameterException", ex);
|
||||
// final ErrorResponse response = ErrorResponse.of(ErrorCode.MISSING_REQUEST_PARAMETER_ERROR, ex.getMessage());
|
||||
// return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * [Exception] 잘못된 서버 요청일 경우 발생한 경우
|
||||
// *
|
||||
// * @param e HttpClientErrorException
|
||||
// * @return ResponseEntity<ErrorResponse>
|
||||
// */
|
||||
// @ExceptionHandler(HttpClientErrorException.BadRequest.class)
|
||||
// protected ResponseEntity<ErrorResponse> handleBadRequestException(HttpClientErrorException e) {
|
||||
// log.error("HttpClientErrorException.BadRequest", e);
|
||||
// final ErrorResponse response = ErrorResponse.of(ErrorCode.BAD_REQUEST_ERROR, e.getMessage());
|
||||
// return new ResponseEntity<>(response, HTTP_STATUS_OK);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * [Exception] 잘못된 주소로 요청 한 경우
|
||||
// *
|
||||
// * @param e NoHandlerFoundException
|
||||
// * @return ResponseEntity<ErrorResponse>
|
||||
// */
|
||||
// @ExceptionHandler(NoHandlerFoundException.class)
|
||||
// protected ResponseEntity<ErrorResponse> handleNoHandlerFoundExceptionException(NoHandlerFoundException e) {
|
||||
// log.error("handleNoHandlerFoundExceptionException", e);
|
||||
// final ErrorResponse response = ErrorResponse.of(ErrorCode.NOT_FOUND_ERROR, e.getMessage());
|
||||
// return new ResponseEntity<>(response, HTTP_STATUS_OK);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * [Exception] NULL 값이 발생한 경우
|
||||
// *
|
||||
// * @param e NullPointerException
|
||||
// * @return ResponseEntity<ErrorResponse>
|
||||
// */
|
||||
// @ExceptionHandler(NullPointerException.class)
|
||||
// protected ResponseEntity<ErrorResponse> handleNullPointerException(NullPointerException e) {
|
||||
// log.error("handleNullPointerException", e);
|
||||
// final ErrorResponse response = ErrorResponse.of(ErrorCode.NULL_POINT_ERROR, e.getMessage());
|
||||
// return new ResponseEntity<>(response, HTTP_STATUS_OK);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Input / Output 내에서 발생한 경우
|
||||
// *
|
||||
// * @param ex IOException
|
||||
// * @return ResponseEntity<ErrorResponse>
|
||||
// */
|
||||
// @ExceptionHandler(IOException.class)
|
||||
// protected ResponseEntity<ErrorResponse> handleIOException(IOException ex) {
|
||||
// log.error("handleIOException", ex);
|
||||
// final ErrorResponse response = ErrorResponse.of(ErrorCode.IO_ERROR, ex.getMessage());
|
||||
// return new ResponseEntity<>(response, HTTP_STATUS_OK);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * com.google.gson 내에 Exception 발생하는 경우
|
||||
// *
|
||||
// * @param ex JsonParseException
|
||||
// * @return ResponseEntity<ErrorResponse>
|
||||
// */
|
||||
// @ExceptionHandler(JsonParseException.class)
|
||||
// protected ResponseEntity<ErrorResponse> handleJsonParseExceptionException(JsonParseException ex) {
|
||||
// log.error("handleJsonParseExceptionException", ex);
|
||||
// final ErrorResponse response = ErrorResponse.of(ErrorCode.JSON_PARSE_ERROR, ex.getMessage());
|
||||
// return new ResponseEntity<>(response, HTTP_STATUS_OK);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * com.fasterxml.jackson.core 내에 Exception 발생하는 경우
|
||||
// *
|
||||
// * @param ex JsonProcessingException
|
||||
// * @return ResponseEntity<ErrorResponse>
|
||||
// */
|
||||
// @ExceptionHandler(JsonProcessingException.class)
|
||||
// protected ResponseEntity<ErrorResponse> handleJsonProcessingException(JsonProcessingException ex) {
|
||||
// log.error("handleJsonProcessingException", ex);
|
||||
// final ErrorResponse response = ErrorResponse.of(ErrorCode.REQUEST_BODY_MISSING_ERROR, ex.getMessage());
|
||||
// return new ResponseEntity<>(response, HTTP_STATUS_OK);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// // ==================================================================================================================
|
||||
//
|
||||
// /**
|
||||
// * [CustomException] WnbtRestException 경우 발생
|
||||
// *
|
||||
// * @param ex WnbtRestException
|
||||
// * @return ResponseEntity<ErrorResponse>
|
||||
// */
|
||||
// @ExceptionHandler(WnbtRestException.class)
|
||||
// protected final ResponseEntity<ErrorResponse> handleAllExceptions(WnbtRestException ex) {
|
||||
// log.error("Exception", ex);
|
||||
// final ErrorResponse response = ErrorResponse.of(ErrorCode.INTERNAL_SERVER_ERROR, ex.getMessage());
|
||||
// return new ResponseEntity<>(response, HTTP_STATUS_OK);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * [CustomException] WnbtPosRestException 경우 발생
|
||||
// *
|
||||
// * @param ex WnbtPosRestException
|
||||
// * @return ResponseEntity<PosResponse>
|
||||
// */
|
||||
// @ExceptionHandler(WnbtPosRestException.class)
|
||||
// protected final ResponseEntity<PosResponse> WnbtPosRestException(WnbtPosRestException ex) {
|
||||
// log.error("WnbtPosRestException", ex);
|
||||
// PosResponse response = PosResponse.builder()
|
||||
// .status(ex.getStatus())
|
||||
// .msg(ex.getMsg())
|
||||
// .data(ex.getData())
|
||||
// .err(ex.getErr())
|
||||
// .build();
|
||||
// return ResponseEntity.status(HTTP_STATUS_OK).body(response);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * [CustomException] WnbtTmRestException 경우 발생
|
||||
// * 추가
|
||||
// * @param ex WnbtPosRestException
|
||||
// * @return ResponseEntity<PosResponse>
|
||||
// */
|
||||
// @ExceptionHandler(WnbtTmRestException.class)
|
||||
// protected final ResponseEntity<TmResponse> WnbtTmRestException(WnbtTmRestException ex) {
|
||||
// log.error("WnbtTmRestException", ex);
|
||||
// TmResponse response = TmResponse.builder()
|
||||
// .result(ex.getResult())
|
||||
// .msg(ex.getMsg())
|
||||
// .data(ex.getData())
|
||||
// .err(ex.getErr())
|
||||
// .build();
|
||||
// return ResponseEntity.status(HTTP_STATUS_OK).body(response);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * [Exception] 모든 Exception 경우 발생
|
||||
// *
|
||||
// * @param ex Exception
|
||||
// * @return ResponseEntity<ErrorResponse>
|
||||
// */
|
||||
// @ExceptionHandler(Exception.class)
|
||||
// protected final ResponseEntity<ErrorResponse> handleAllExceptions(Exception ex) {
|
||||
// log.error("Exception", ex);
|
||||
// final ErrorResponse response = ErrorResponse.of(ErrorCode.INTERNAL_SERVER_ERROR, ex.getMessage());
|
||||
// return new ResponseEntity<>(response, HTTP_STATUS_OK);
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.wb.domainserver.exception;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
@ResponseStatus(HttpStatus.NOT_FOUND)
|
||||
@SuppressWarnings("serial")
|
||||
public class MyFileNotFoundException extends RuntimeException {
|
||||
|
||||
public MyFileNotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
public MyFileNotFoundException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.wb.domainserver.exception;
|
||||
|
||||
import com.wb.domainserver.exception.code.ErrCode;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class WnbtException extends RuntimeException {
|
||||
private String code;
|
||||
private String codeNumber;
|
||||
private ErrCode errCode;
|
||||
|
||||
public WnbtException(){}
|
||||
|
||||
public WnbtException(String code, String message){
|
||||
super(message);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public WnbtException(ErrCode errCode) {
|
||||
super(errCode.getMessage());
|
||||
this.code = String.valueOf(errCode.getStatus());
|
||||
this.codeNumber = String.valueOf(errCode.getStatusCode());
|
||||
this.errCode = errCode;
|
||||
}
|
||||
|
||||
public WnbtException(ErrCode errCode, String customMessage) {
|
||||
super(customMessage);
|
||||
this.code = String.valueOf(errCode.getStatus());
|
||||
this.codeNumber = String.valueOf(errCode.getStatusCode());
|
||||
this.errCode = errCode;
|
||||
}
|
||||
|
||||
public WnbtException(String message, Throwable cause){
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.wb.domainserver.exception;
|
||||
|
||||
import com.wb.domainserver.domain.gcone.goods.purchs.vo.BOOrderLogVO;
|
||||
import com.wb.domainserver.domain.gcone.ordr.ordr.service.BOOrdrLogService;
|
||||
import com.wb.domainserver.exception.code.OrderBellCode;
|
||||
import java.math.BigInteger;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class WnbtOrderBellRestException extends RuntimeException {
|
||||
private String code;
|
||||
private OrderBellCode bellCode;
|
||||
|
||||
private BOOrdrLogService ordrLogService;
|
||||
|
||||
|
||||
public WnbtOrderBellRestException(String ordrInnb, String sopmalCd, OrderBellCode bellCode) {
|
||||
super(bellCode.getMessage());
|
||||
insertLog(ordrInnb, sopmalCd, bellCode.getMessage()); // 예외 발생 시 로그 자동 기록
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ordrInnb
|
||||
* @param message
|
||||
*/
|
||||
private void insertLog(String ordrInnb, String sopmalCd, String message) {
|
||||
BOOrderLogVO bellVO = new BOOrderLogVO();
|
||||
bellVO.setOrdrInnb(new BigInteger(ordrInnb));
|
||||
bellVO.setSopmalCd(sopmalCd);
|
||||
ordrLogService.insertBOOrderBellLogRegist(bellVO);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.wb.domainserver.exception;
|
||||
|
||||
import com.wb.domainserver.exception.code.PosCode;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
public class WnbtPosRestException extends RuntimeException{
|
||||
/*에러여부*/
|
||||
private String status;
|
||||
/*메시지*/
|
||||
private String msg;
|
||||
private Object data;
|
||||
/*에러메시지 영문*/
|
||||
private String err;
|
||||
|
||||
public WnbtPosRestException(PosCode posCode) {
|
||||
super(posCode.getMsg());
|
||||
this.status = posCode.getStatus();
|
||||
this.msg = posCode.getMsg();
|
||||
this.err = posCode.getErr();
|
||||
}
|
||||
|
||||
public WnbtPosRestException(PosCode posCode, String customMsg, String customErr) {
|
||||
super(customMsg+posCode.getMsg());
|
||||
this.status = posCode.getStatus();
|
||||
this.msg = customMsg + posCode.getMsg();
|
||||
this.err = posCode.getErr() + customErr;
|
||||
}
|
||||
|
||||
public WnbtPosRestException(PosCode posCode, Object data) {
|
||||
super(posCode.getMsg());
|
||||
this.status = posCode.getStatus();
|
||||
this.data = data;
|
||||
this.err = posCode.getErr();
|
||||
}
|
||||
|
||||
|
||||
public WnbtPosRestException(PosCode posCode, String customMsg, String customErr, Object data) {
|
||||
super(customMsg+posCode.getMsg());
|
||||
this.status = posCode.getStatus();
|
||||
this.msg = customMsg + posCode.getMsg();
|
||||
this.data = data;
|
||||
this.err = posCode.getErr() + customErr;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.wb.domainserver.exception;
|
||||
|
||||
import com.wb.domainserver.exception.code.ErrorCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class WnbtRestException extends RuntimeException {
|
||||
private String code;
|
||||
private ErrorCode errCode;
|
||||
|
||||
public WnbtRestException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public WnbtRestException(String code, String message) {
|
||||
super(message);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public WnbtRestException(ErrorCode errCode) {
|
||||
super(errCode.getMessage());
|
||||
this.code = String.valueOf(errCode.getStatus());
|
||||
this.errCode = errCode;
|
||||
}
|
||||
|
||||
public WnbtRestException(ErrorCode errCode, String customMessage) {
|
||||
super(customMessage);
|
||||
this.code = String.valueOf(errCode.getStatus());
|
||||
this.errCode = errCode;
|
||||
}
|
||||
|
||||
|
||||
public WnbtRestException(String message, Throwable cause){
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.wb.domainserver.exception;
|
||||
|
||||
import com.wb.domainserver.exception.code.ErrCode;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class WnbtWebClientException extends RuntimeException{
|
||||
private String code;
|
||||
private String codeNumber;
|
||||
private ErrCode errCode;
|
||||
|
||||
public WnbtWebClientException(){}
|
||||
|
||||
public WnbtWebClientException(String code, String message){
|
||||
super(message);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public WnbtWebClientException(ErrCode errCode) {
|
||||
super(errCode.getMessage());
|
||||
this.code = String.valueOf(errCode.getStatus());
|
||||
this.codeNumber = String.valueOf(errCode.getStatusCode());
|
||||
this.errCode = errCode;
|
||||
}
|
||||
|
||||
public WnbtWebClientException(ErrCode errCode, String customMessage) {
|
||||
super(customMessage);
|
||||
this.code = String.valueOf(errCode.getStatus());
|
||||
this.codeNumber = String.valueOf(errCode.getStatusCode());
|
||||
this.errCode = errCode;
|
||||
}
|
||||
|
||||
public WnbtWebClientException(String message, Throwable cause){
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.wb.domainserver.exception.advice;
|
||||
|
||||
import com.wb.domainserver.exception.code.ErrCode;
|
||||
import com.wb.domainserver.exception.WnbtException;
|
||||
import com.wb.domainserver.exception.WnbtRestException;
|
||||
import com.wb.domainserver.exception.WnbtWebClientException;
|
||||
import com.wb.domainserver.response.WnbtResponse;
|
||||
import com.wb.domainserver.response.WnbtResponseBody;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.oauth2.client.ClientAuthorizationRequiredException;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.multipart.MaxUploadSizeExceededException;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
@Slf4j
|
||||
@ControllerAdvice
|
||||
public class GlobalExceptionControllerAdvice {
|
||||
|
||||
public static final String DEFAULT_ERROR_VIEW = "error";
|
||||
|
||||
@ExceptionHandler(value = WnbtException.class)
|
||||
public ModelAndView customErrorHandler(HttpServletRequest req, WnbtException e){
|
||||
ModelAndView mav = new ModelAndView();
|
||||
mav.addObject("status", e.getCodeNumber());
|
||||
mav.addObject("url", req.getRequestURI());
|
||||
mav.addObject("errorCode", e.getCode());
|
||||
mav.addObject("errorMessage", e.getMessage());
|
||||
mav.setViewName(DEFAULT_ERROR_VIEW);
|
||||
return mav;
|
||||
}
|
||||
|
||||
@ExceptionHandler(value = WnbtRestException.class)
|
||||
public ResponseEntity<WnbtResponse> ajaxErrorHandler(HttpServletRequest req, HttpServletResponse res, WnbtRestException e){
|
||||
WnbtResponse wnbtResponse = WnbtResponse.builder()
|
||||
.statusCode(res.getStatus())
|
||||
.requestUrl(String.valueOf(req.getRequestURL()))
|
||||
.resBody(new WnbtResponseBody(e.getMessage()))
|
||||
.build();
|
||||
|
||||
return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY).body(wnbtResponse);
|
||||
//422 : 서버가 요청을 이해하고 요청 문법도 올바르지만 요청된 지시를 따를 수 없음을 나타냄
|
||||
//요청 데이터에 대해 validation 처리를 하면서 적합하지 않은 데이터를 받았을 때 반환
|
||||
}
|
||||
|
||||
@ExceptionHandler(value = Exception.class)
|
||||
public ModelAndView defaultErrorHandler(HttpServletRequest req, Exception e) throws Exception {
|
||||
if(e instanceof ClientAuthorizationRequiredException){
|
||||
throw e;
|
||||
}
|
||||
ModelAndView mav = new ModelAndView();
|
||||
mav.addObject("errorMessage", e.getMessage());
|
||||
mav.addObject("url", req.getRequestURL());
|
||||
mav.addObject("status", ErrCode.INTERNAL_SEVER_ERROR.getStatusCode());
|
||||
mav.setViewName(DEFAULT_ERROR_VIEW);
|
||||
return mav;
|
||||
}
|
||||
|
||||
|
||||
@ExceptionHandler(value = MaxUploadSizeExceededException.class)
|
||||
public ResponseEntity<WnbtResponse> handleMaxSizeException(HttpServletRequest req, HttpServletResponse res, MaxUploadSizeExceededException e) {
|
||||
WnbtResponse wnbtResponse = WnbtResponse.builder()
|
||||
.statusCode(res.getStatus())
|
||||
.requestUrl(String.valueOf(req.getRequestURL()))
|
||||
.resBody(new WnbtResponseBody(e))
|
||||
.build();
|
||||
|
||||
return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY).body(wnbtResponse);
|
||||
}
|
||||
|
||||
@ExceptionHandler(value = WnbtWebClientException.class)
|
||||
public ResponseEntity<WnbtResponse> WebClientException(HttpServletRequest req, HttpServletResponse res, WnbtWebClientException e) {
|
||||
WnbtResponse wnbtResponse = WnbtResponse.builder()
|
||||
.statusCode(res.getStatus())
|
||||
.requestUrl(String.valueOf(req.getRequestURL()))
|
||||
.resBody(new WnbtResponseBody(e.getMessage()))
|
||||
.build();
|
||||
return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY).body(wnbtResponse);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.wb.domainserver.exception.code;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ErrCode {
|
||||
|
||||
//APPLICATION_SERVER_ERROR
|
||||
PAGE_NOT_FOUND(HttpStatus.NOT_FOUND, HttpStatus.NOT_FOUND.value(), "페이지를 찾을수 없습니다"),
|
||||
BAD_REQUEST(HttpStatus.BAD_REQUEST, HttpStatus.BAD_REQUEST.value(), "잘못된 요청입니다"),
|
||||
NOT_AUTHENTICATED(HttpStatus.UNAUTHORIZED, HttpStatus.UNAUTHORIZED.value(), "인증이 필요한 요청입니다"),
|
||||
INVALID_PERMISSION(HttpStatus.FORBIDDEN, HttpStatus.FORBIDDEN.value(), "해당 요청에 권한이 없습니다"),
|
||||
METHOD_NOT_ALLOWED(HttpStatus.METHOD_NOT_ALLOWED, HttpStatus.METHOD_NOT_ALLOWED.value(), "허용되지 않는 요청 메소드입니다"),
|
||||
REQUEST_TIMEOUT(HttpStatus.REQUEST_TIMEOUT, HttpStatus.REQUEST_TIMEOUT.value(), "요청 시간이 만료되었습니다."),
|
||||
|
||||
//DATABASE_TRANSACTION_ERROR
|
||||
DUPLICATED_USER_NAME(HttpStatus.CONFLICT, HttpStatus.CONFLICT.value(), "유저명이 중복됩니다"),
|
||||
|
||||
//INTERNAL_SERVER_ERROR,
|
||||
INTERNAL_SEVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, HttpStatus.INTERNAL_SERVER_ERROR.value(), "실행 도중 예기치 못한 오류가 발생하였습니다"),
|
||||
USERNAME_NOT_FOUND(HttpStatus.INTERNAL_SERVER_ERROR, HttpStatus.INTERNAL_SERVER_ERROR.value(), "유저를 찾을 수 없습니다"),
|
||||
DATABASE_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, HttpStatus.INTERNAL_SERVER_ERROR.value(), "Database 에러가 발생하였습니다");
|
||||
|
||||
private HttpStatus status;
|
||||
private int statusCode;
|
||||
private String message;
|
||||
}
|
||||
107
src/main/java/com/wb/domainserver/exception/code/ErrorCode.java
Normal file
107
src/main/java/com/wb/domainserver/exception/code/ErrorCode.java
Normal file
@@ -0,0 +1,107 @@
|
||||
package com.wb.domainserver.exception.code;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* [공통 코드] API 통신에 대한 '에러 코드'를 Enum 형태로 관리를 한다.
|
||||
* Global Error CodeList : 전역으로 발생하는 에러코드를 관리한다.
|
||||
* Custom Error CodeList : 업무 페이지에서 발생하는 에러코드를 관리한다
|
||||
* Error Code Constructor : 에러코드를 직접적으로 사용하기 위한 생성자를 구성한다.
|
||||
*
|
||||
* @author hjin1210
|
||||
*/
|
||||
@Getter
|
||||
public enum ErrorCode {
|
||||
|
||||
/**
|
||||
* ******************************* Global Error CodeList ***************************************
|
||||
* HTTP Status Code
|
||||
* 400 : Bad Request
|
||||
* 401 : Unauthorized
|
||||
* 403 : Forbidden
|
||||
* 404 : Not Found
|
||||
* 500 : Internal Server Error
|
||||
* *********************************************************************************************
|
||||
*/
|
||||
// 잘못된 서버 요청
|
||||
BAD_REQUEST_ERROR(400, "G001", "Bad Request Exception"),
|
||||
|
||||
// @RequestBody 데이터 미 존재
|
||||
REQUEST_BODY_MISSING_ERROR(400, "G002", "Required request body is missing"),
|
||||
|
||||
// 유효하지 않은 타입
|
||||
INVALID_TYPE_VALUE(400, "G003", " Invalid Type Value"),
|
||||
|
||||
// Request Parameter 로 데이터가 전달되지 않을 경우
|
||||
MISSING_REQUEST_PARAMETER_ERROR(400, "G004", "Missing Servlet RequestParameter Exception"),
|
||||
|
||||
// 입력/출력 값이 유효하지 않음
|
||||
IO_ERROR(400, "G005", "I/O Exception"),
|
||||
|
||||
// com.google.gson JSON 파싱 실패
|
||||
JSON_PARSE_ERROR(400, "G006", "JsonParseException"),
|
||||
|
||||
// com.fasterxml.jackson.core Processing Error
|
||||
JACKSON_PROCESS_ERROR(400, "G007", "com.fasterxml.jackson.core Exception"),
|
||||
|
||||
// 권한이 없음
|
||||
FORBIDDEN_ERROR(403, "G008", "Forbidden Exception"),
|
||||
|
||||
// 서버로 요청한 리소스가 존재하지 않음
|
||||
NOT_FOUND_ERROR(404, "G009", "Not Found Exception"),
|
||||
|
||||
// NULL Point Exception 발생
|
||||
NULL_POINT_ERROR(404, "G010", "Null Point Exception"),
|
||||
|
||||
// @RequestBody 및 @RequestParam, @PathVariable 값이 유효하지 않음
|
||||
NOT_VALID_ERROR(404, "G011", "handle Validation Exception"),
|
||||
|
||||
// @RequestBody 및 @RequestParam, @PathVariable 값이 유효하지 않음
|
||||
NOT_VALID_HEADER_ERROR(404, "G012", "Header에 데이터가 존재하지 않는 경우 "),
|
||||
|
||||
//jwt 파싱에러
|
||||
JWT_ACCESS_PARSE_ERROR(500, "G013", "JwtAccessParseException"),
|
||||
JWT_REFRESH_PARSE_ERROR(500, "G014", "JwtRefreshParseException"),
|
||||
JWT_ACCESS_EXPIRED_ERROR(401, "G013", "JwtAccessExpiredException"),
|
||||
JWT_REFRESH_EXPIRED_ERROR(401, "G014", "JwtRefreshExpiredException"),
|
||||
JWT_ACCESS_ERROR(500, "G014", "JwtAccessException"),
|
||||
JWT_AUTHENTICATION_FAIL(401, "G015", "token authentication fail"),
|
||||
|
||||
|
||||
// 서버가 처리 할 방법을 모르는 경우 발생
|
||||
INTERNAL_SERVER_ERROR(500, "G999", "Internal Server Error Exception"),
|
||||
|
||||
|
||||
/**
|
||||
* ******************************* Custom Error CodeList ***************************************
|
||||
*/
|
||||
// Transaction Insert Error
|
||||
INSERT_ERROR(200, "9999", "Insert Transaction Error Exception"),
|
||||
|
||||
// Transaction Update Error
|
||||
UPDATE_ERROR(200, "9999", "Update Transaction Error Exception"),
|
||||
|
||||
// Transaction Delete Error
|
||||
DELETE_ERROR(200, "9999", "Delete Transaction Error Exception"),
|
||||
|
||||
; // End
|
||||
|
||||
/**
|
||||
* ******************************* Error Code Constructor ***************************************
|
||||
*/
|
||||
// 에러 코드의 '코드 상태'을 반환한다.
|
||||
private final int status;
|
||||
|
||||
// 에러 코드의 '코드간 구분 값'을 반환한다.
|
||||
private final String divisionCode;
|
||||
|
||||
// 에러 코드의 '코드 메시지'을 반환한다.
|
||||
private final String message;
|
||||
|
||||
// 생성자 구성
|
||||
ErrorCode(final int status, final String divisionCode, final String message) {
|
||||
this.status = status;
|
||||
this.divisionCode = divisionCode;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.wb.domainserver.exception.code;
|
||||
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum OrderBellCode {
|
||||
|
||||
|
||||
// 재고 갱신 단계 오류
|
||||
INVENTORY_UPDATE_FAILED("O-INV-001", "상품 재고 갱신 실패"),
|
||||
|
||||
// 메시지(알림) 전송 단계 오류
|
||||
MESSAGE_SEND_FAILED("O-MSG-001", "주문 알림 발송 실패"),
|
||||
|
||||
// 주문 저장 단계 오류
|
||||
ORDER_SAVE_FAILED("O-ORD-001", "주문 저장 실패"),
|
||||
|
||||
// 결제 단계 오류
|
||||
PAYMENT_PROCESS_FAILED("O-PAY-001", "결제 처리 실패");
|
||||
|
||||
|
||||
private final String code;
|
||||
private final String message;
|
||||
|
||||
|
||||
OrderBellCode(final String code, final String msgCode){
|
||||
this.code = code;
|
||||
this.message = msgCode;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.wb.domainserver.exception.code;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum PosCode {
|
||||
|
||||
/**
|
||||
* ******************************* PosCode CodeList ***************************************
|
||||
*/
|
||||
NO_UID("N", "회원을 지정해 주세요", "no uid"),
|
||||
NO_MEMBER_SEQ("N", "회원정보를 확인할 수 없습니다.", "no_member_seq"),
|
||||
NO_SEARCH_ITEM("N", "검색 항목을 지정해 주세요", "no_search_item"),
|
||||
BAD_SEARCH_ITEM("N", "검색 항목이 올바르지 않습니다", "Bad search_item"),
|
||||
NO_STORE_INFO("N", "매장정보를 확인 할 수 없습니다", "no store info"),
|
||||
NO_EW_STORE("N", "이지웰페이 미적용 매장입니다", "NO_EW_STORE"),
|
||||
INTERNAL_SERVER_ERROR("N", "서버 에러가 발생하였습니다.", "internal server error"),
|
||||
INPUT_CHECK("N", " 정보를 입력해 주세요", "NO "),
|
||||
NO_ORDER_INFO("N", "취소할 원거래 주문 정보가 없습니다.", "no cancel_order_data"),
|
||||
ALREADY_ORDER_INFO("N", "이미 매출정보가 저장되었습니다.", "have information already"),
|
||||
ALREADY_REFUNDED_ORDER("N", "이미 취소 처리된 반품 건입니다.", "refund already processed"),
|
||||
NO_RETURN_CODE("N", "반품 저장에 실패했습니다.(반품코드 오류)", "no return_code"),
|
||||
FAIL_DB_RETURN("N", "반품 저장에 실패했습니다.", "DB fail return"),
|
||||
FAIL_DB_ORDER("N", "주문 오류입니다.", "DB fail order"),
|
||||
NO_OPTION_SEQ("N", "주문상품 저장에 실패했습니다.", "no option_seq"),
|
||||
NO_COUPON_ARR("N", "쿠폰 목록이 지정되지 않았습니다.", "no coupon_arr"),
|
||||
NO_MASTER("N", "매출 정보를 입력해 주세요.(master)", "no master"),
|
||||
NO_DETAIL_ARR("N", "매출 상세정보를 입력해 주세요.(detail_arr)", "no detail_arr"),
|
||||
NO_CANCEL_ORDER_DATA("N", "취소할 원거래 주문 정보가 없습니다.", "no cancel_order_data"),
|
||||
TOO_MANY_RESULT("N", "검색결과가 너무 많습니다.\n\n아이디 또는 휴대폰으로 검색해 주세요.", "too_many_result"),
|
||||
BAD_SEARCH_KEY("N", "검색어가 올바르지 않습니다.(4자리, 8자리, 전체)", "bad_search_key"),
|
||||
BAD_CONSUMER("N", "판매금지 고객입니다.", "bad_consumer"),
|
||||
CMD_FAIL("N", "작업 명령이 올바르지 않습니다", "cmd fail"),
|
||||
CUSTOM_MSG("N", "", ""),
|
||||
FROM_DATE("N", "검색 기간의 시작일을 지정해 주세요.", "no_from_date"),
|
||||
TO_DATE("N", "검색 기간의 종료일을 지정해 주세요.", "no_to_date"),
|
||||
SOCKET_TIME_OUT("N", "통신 시간이 초과하였습니다", "socket_time_out"),
|
||||
;
|
||||
|
||||
|
||||
/*에러여부*/
|
||||
private final String status;
|
||||
/*메시지*/
|
||||
private final String msg;
|
||||
/*에러메시지 영문*/
|
||||
private final String err;
|
||||
|
||||
|
||||
|
||||
|
||||
PosCode(final String status, final String msg, final String err) {
|
||||
this.status = status;
|
||||
this.msg = msg;
|
||||
this.err = err;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.wb.domainserver.exception.code;
|
||||
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum PurchsValidCode {
|
||||
|
||||
/** msgCode 패턴
|
||||
* GC + 년도 2글자 + valid 첫번째 영문 앞 1 + 월 + valid 두번째 영문 앞 1 + 일 ... 시퀀셜 번호 세자리 */
|
||||
|
||||
NOT_EXIST_COUPON_LIST( "notExistCouponList", "GC25N03E24C10L001","보유하지 않는 쿠폰번호 존재"),
|
||||
GOODS_STTUS("goodsSttus","GC25G03S24002", "판매 불가능한 상품 상태"),
|
||||
PURCHS_QY_LMTT("purchsQyLmtt","GC25P03Q24L003","상품 구매 수량 제한(주문당 구매수량) 초과"),
|
||||
INVNTRY("invntry","GC25I0324004","옵션 재고 부족"),
|
||||
INVNTRY_POLICY("invntryPolicy","GC25I03P24005","상품 재고정책에 따른 상품별 옵션 수량합산 재고 부족"),
|
||||
SELPRIC("selpric","GC25S0324006","판매가 불일치"),
|
||||
DSCNT_AT("dscntAt","GC25D03A24007","구간/복수할인 정보 불일치"),
|
||||
DLVY_GROUP("dlvyGroup","GC25D03G24008","배송그룹 고유번호 불일치"),
|
||||
PURCHS_TRGTER_LMTT("purchsTrgterLmtt","GC25P03T24L009","구매대상자제한 대상"),
|
||||
USE_MLG_AT("useMlgAt","GC25U03M24A010","마일리지 보유금액 초과 사용"),
|
||||
COUPON_STTUS("couponSttus","GC25C03S24011", "사용 불가능한 쿠폰 존재"),
|
||||
COUPON_USE_AT("couponUseAt","GC25C03U24A012","회수(사용불가) 되어진 쿠폰 존재"),
|
||||
COUPON_VALIDPD_DT("couponValidpdDt","GC25CO3V24D013","사용기간 지난 쿠폰 존재"),
|
||||
DO_NOT_HAVE_COUPON("doNotHaveCoupon", "GC25D03N25HC014","보유하지 않은 쿠폰 존재"),
|
||||
EVT_TRGET_AT("evtTrgetAt","GC25E03T24A014","이벤트 대상 상품 아님"),
|
||||
DPLCT_LMTT_COUPON("dplctLmttCoupon","GC25D03L24C015","이벤트 중복제한 쿠폰 존재"),
|
||||
PURCHS_TOTAL_AMT("setleAmt","GC25P03T24A016","주문 요청 총 결제금액과 계산된 총 결제금액 불일치"),
|
||||
USE_CASH_MLG_AT("useCashMlgAt","GC25U06C26M017","GC 머니 보유금액 초과 사용")
|
||||
|
||||
;
|
||||
|
||||
private static final String DEFAULT_MSG = "구매정보가 변경 되었습니다. 다시 시도해 주세요. ";
|
||||
|
||||
/*구매상태 코드*/
|
||||
private final String code;
|
||||
|
||||
/*사용자 메시지 코드*/
|
||||
private final String msg;
|
||||
|
||||
/*구매 에러 내용*/
|
||||
private final String description;
|
||||
|
||||
|
||||
PurchsValidCode(final String code, final String msgCode, final String description){
|
||||
this.code = code;
|
||||
this.msg = DEFAULT_MSG + "(" + msgCode + ")";
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
|
||||
public static String purchsValidMsg(String code){
|
||||
String returnMsg = DEFAULT_MSG;
|
||||
for(PurchsValidCode value : PurchsValidCode.values()){
|
||||
|
||||
if(code.equals(value.getCode())){
|
||||
|
||||
returnMsg = value.getMsg();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
return returnMsg;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.wb.domainserver.exception.code;
|
||||
|
||||
import lombok.Getter;
|
||||
/**
|
||||
* [공통 코드] API 통신에 대한 '에러 코드'를 Enum 형태로 관리를 한다.
|
||||
* Success CodeList : 성공 코드를 관리한다.
|
||||
* Success Code Constructor: 성공 코드를 사용하기 위한 생성자를 구성한다.
|
||||
*
|
||||
* @author hjin1210
|
||||
*/
|
||||
@Getter
|
||||
public enum SuccessCode {
|
||||
|
||||
/**
|
||||
* ******************************* Success CodeList ***************************************
|
||||
*/
|
||||
// 조회 성공 코드 (HTTP Response: 200 OK)
|
||||
SELECT_SUCCESS(200, "200", "SELECT SUCCESS"),
|
||||
// 삭제 성공 코드 (HTTP Response: 200 OK)
|
||||
DELETE_SUCCESS(200, "200", "DELETE SUCCESS"),
|
||||
// 삽입 성공 코드 (HTTP Response: 201 Created)
|
||||
INSERT_SUCCESS(201, "201", "INSERT SUCCESS"),
|
||||
// 수정 성공 코드 (HTTP Response: 201 Created)
|
||||
UPDATE_SUCCESS(204, "204", "UPDATE SUCCESS"),
|
||||
|
||||
; // End
|
||||
|
||||
/**
|
||||
* ******************************* Success Code Constructor ***************************************
|
||||
*/
|
||||
// 성공 코드의 '코드 상태'를 반환한다.
|
||||
private final int status;
|
||||
|
||||
// 성공 코드의 '코드 값'을 반환한다.
|
||||
private final String code;
|
||||
|
||||
// 성공 코드의 '코드 메시지'를 반환한다.s
|
||||
private final String message;
|
||||
|
||||
// 생성자 구성
|
||||
SuccessCode(final int status, final String code, final String message) {
|
||||
this.status = status;
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
53
src/main/java/com/wb/domainserver/exception/code/TmCode.java
Normal file
53
src/main/java/com/wb/domainserver/exception/code/TmCode.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package com.wb.domainserver.exception.code;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public enum TmCode {
|
||||
|
||||
/**
|
||||
* ******************************* TmCode CodeList ***************************************
|
||||
*/
|
||||
INTERNAL_SERVER_ERROR("N", "서버 에러가 발생하였습니다.", "internal server error"),
|
||||
/*회원 정보 관련*/
|
||||
NO_USER_NAME("N", "회원명이 지정되지 않았습니다.(NO_USER_NAME)", ""),
|
||||
NO_CELLPHONE("N", "휴대전화가 지정되지 않았습니다.(NO_CELLPHONE)", ""),
|
||||
BAD_CELLPHONE("N", "휴대전화가 올바르지 않습니다.(BAD_CELLPHONE)", ""),
|
||||
BAD_LEN_CELLPHONE("N", "휴대전화 길이가 올바르지 않습니다.(BAD_LEN_CELLPHONE)", ""),
|
||||
NO_MEMBER_INFO("N", "회원 정보를 확인할 수 없습니다.(NO_MEMBER_INFO)", ""),
|
||||
|
||||
/*주문 관련*/
|
||||
NO_ORDER_SEQ("N","주문이 지정되지 않았습니다.(NO_ORDER_SEQ)",""),
|
||||
NO_BRAND_CD("N","쇼핑몰이 지정되지 않았습니다.(NO_BRAND_CD)",""),
|
||||
NO_DATA("N","주문 정보를 확인할 수 없습니다.(NO_DATA)",""),
|
||||
FAIL_UPDATE("N","수정 실패하였습니다.(FAIL_DATA)",""),
|
||||
NO_MEMBER_SEQ("N","대상이 지정되지 않았습니다.(NO_MEMBER_SEQ)",""),
|
||||
NO_VALIDATE_ORDER("N","주문이 유효하지 않으므로 수정하실 수 없습니다.",""),
|
||||
NO_UPDATE("N","이미 출고가 진행중이므로 수정하실 수 없습니다.",""),
|
||||
|
||||
/*상품 관련*/
|
||||
NO_GOODS_SEQ("N","상품이 지정되지 않았습니다.(NO_GOODS_SEQ)",""),
|
||||
NO_GOODS_INFO("N","상품 정보를 확인할 수 없습니다.(NO_GOODS_INFO)",""),
|
||||
NO_GIFT_DATA("N","사은품 이벤트 정보를 확인할 수 없습니다.(NO_DATA)",""),
|
||||
|
||||
/*공통*/
|
||||
CUSTOM_MSG("N","","");
|
||||
;
|
||||
|
||||
|
||||
/*에러여부*/
|
||||
private final String result;
|
||||
/*메시지*/
|
||||
private final String msg;
|
||||
/*에러메시지 영문*/
|
||||
private final String err;
|
||||
|
||||
|
||||
|
||||
TmCode(final String result, final String msg, final String err) {
|
||||
this.result = result;
|
||||
this.msg = msg;
|
||||
this.err = err;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.wb.domainserver.exception.response;
|
||||
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
@Slf4j
|
||||
public class CustomOauthFailureException implements AuthenticationFailureHandler {
|
||||
|
||||
/*앨리스랩 회원 정보 없을 시 예외처리*/
|
||||
@Override
|
||||
public void onAuthenticationFailure(HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
AuthenticationException exception) throws IOException, ServletException {
|
||||
String msg = exception.getMessage();
|
||||
|
||||
response.setContentType("text/html; charset=UTF-8");
|
||||
PrintWriter out = response.getWriter();
|
||||
out.println("<script>");
|
||||
out.println("if (window.opener && !window.opener.closed) {");
|
||||
out.println(" window.close();");
|
||||
out.println(" window.opener.oauthFailureAlert('"+msg+"'); }");
|
||||
out.println("</script>");
|
||||
out.flush();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package com.wb.domainserver.exception.response;
|
||||
|
||||
import com.wb.domainserver.exception.code.ErrorCode;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.validation.BindingResult;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Global Exception Handler에서 발생한 에러에 대한 응답 처리를 관리
|
||||
*/
|
||||
@Getter
|
||||
@NoArgsConstructor(access = AccessLevel.PROTECTED)
|
||||
public class ErrorResponse {
|
||||
private int status; // 에러 상태 코드
|
||||
private String divisionCode; // 에러 구분 코드
|
||||
private String resultMsg; // 에러 메시지
|
||||
private List<FieldError> errors; // 상세 에러 메시지
|
||||
private String reason; // 에러 이유
|
||||
|
||||
/**
|
||||
* ErrorResponse 생성자-1
|
||||
*
|
||||
* @param code ErrorCode
|
||||
*/
|
||||
@Builder
|
||||
protected ErrorResponse(final ErrorCode code) {
|
||||
this.resultMsg = code.getMessage();
|
||||
this.status = code.getStatus();
|
||||
this.divisionCode = code.getDivisionCode();
|
||||
this.errors = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* ErrorResponse 생성자-2
|
||||
*
|
||||
* @param code ErrorCode
|
||||
* @param reason String
|
||||
*/
|
||||
@Builder
|
||||
protected ErrorResponse(final ErrorCode code, final String reason) {
|
||||
this.resultMsg = code.getMessage();
|
||||
this.status = code.getStatus();
|
||||
this.divisionCode = code.getDivisionCode();
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
/**
|
||||
* ErrorResponse 생성자-3
|
||||
*
|
||||
* @param code ErrorCode
|
||||
* @param errors List<FieldError>
|
||||
*/
|
||||
@Builder
|
||||
protected ErrorResponse(final ErrorCode code, final List<FieldError> errors) {
|
||||
this.resultMsg = code.getMessage();
|
||||
this.status = code.getStatus();
|
||||
this.errors = errors;
|
||||
this.divisionCode = code.getDivisionCode();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Global Exception 전송 타입-1
|
||||
*
|
||||
* @param code ErrorCode
|
||||
* @param bindingResult BindingResult
|
||||
* @return ErrorResponse
|
||||
*/
|
||||
public static ErrorResponse of(final ErrorCode code, final BindingResult bindingResult) {
|
||||
return new ErrorResponse(code, FieldError.of(bindingResult));
|
||||
}
|
||||
|
||||
/**
|
||||
* Global Exception 전송 타입-2
|
||||
*
|
||||
* @param code ErrorCode
|
||||
* @return ErrorResponse
|
||||
*/
|
||||
public static ErrorResponse of(final ErrorCode code) {
|
||||
return new ErrorResponse(code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Global Exception 전송 타입-3
|
||||
*
|
||||
* @param code ErrorCode
|
||||
* @param reason String
|
||||
* @return ErrorResponse
|
||||
*/
|
||||
public static ErrorResponse of(final ErrorCode code, final String reason) {
|
||||
return new ErrorResponse(code, reason);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 에러를 e.getBindingResult() 형태로 전달 받는 경우 해당 내용을 상세 내용으로 변경하는 기능을 수행한다.
|
||||
*/
|
||||
@Getter
|
||||
public static class FieldError {
|
||||
private final String field;
|
||||
private final String value;
|
||||
private final String reason;
|
||||
|
||||
public static List<FieldError> of(final String field, final String value, final String reason) {
|
||||
List<FieldError> fieldErrors = new ArrayList<>();
|
||||
fieldErrors.add(new FieldError(field, value, reason));
|
||||
return fieldErrors;
|
||||
}
|
||||
|
||||
private static List<FieldError> of(final BindingResult bindingResult) {
|
||||
final List<org.springframework.validation.FieldError> fieldErrors = bindingResult.getFieldErrors();
|
||||
return fieldErrors.stream()
|
||||
.map(error -> new FieldError(
|
||||
error.getField(),
|
||||
error.getRejectedValue() == null ? "" : error.getRejectedValue().toString(),
|
||||
error.getDefaultMessage()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Builder
|
||||
FieldError(String field, String value, String reason) {
|
||||
this.field = field;
|
||||
this.value = value;
|
||||
this.reason = reason;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.wb.domainserver.exception.response;
|
||||
|
||||
import com.wb.domainserver.exception.code.PosCode;
|
||||
import com.wb.domainserver.exception.code.TmCode;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
public class WnbtTmRestException extends RuntimeException{
|
||||
/*에러여부 */
|
||||
private String result;
|
||||
/*메시지*/
|
||||
private String msg;
|
||||
private Object data;
|
||||
/*에러메시지 영문*/
|
||||
private String err;
|
||||
|
||||
public WnbtTmRestException(TmCode tmCode) {
|
||||
super(tmCode.getMsg());
|
||||
this.result = tmCode.getResult();
|
||||
this.msg = tmCode.getMsg();
|
||||
this.err = tmCode.getErr();
|
||||
}
|
||||
|
||||
public WnbtTmRestException(TmCode tmCode, String customMsg, String customErr) {
|
||||
super(customMsg+tmCode.getMsg());
|
||||
this.result = tmCode.getResult();
|
||||
this.msg = customMsg + tmCode.getMsg();
|
||||
this.err = tmCode.getErr() + customErr;
|
||||
}
|
||||
|
||||
public WnbtTmRestException(TmCode tmCode, Object data) {
|
||||
super(tmCode.getMsg());
|
||||
this.result = tmCode.getResult();
|
||||
this.data = data;
|
||||
this.err = tmCode.getErr();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user