초기소스
This commit is contained in:
@@ -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);
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user