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 // */ // @ExceptionHandler(MethodArgumentNotValidException.class) // protected ResponseEntity 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 // */ // @ExceptionHandler(MissingRequestHeaderException.class) // protected ResponseEntity 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 // */ // @ExceptionHandler(HttpMessageNotReadableException.class) // protected ResponseEntity 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 // */ // @ExceptionHandler(MissingServletRequestParameterException.class) // protected ResponseEntity 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 // */ // @ExceptionHandler(HttpClientErrorException.BadRequest.class) // protected ResponseEntity 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 // */ // @ExceptionHandler(NoHandlerFoundException.class) // protected ResponseEntity 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 // */ // @ExceptionHandler(NullPointerException.class) // protected ResponseEntity 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 // */ // @ExceptionHandler(IOException.class) // protected ResponseEntity 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 // */ // @ExceptionHandler(JsonParseException.class) // protected ResponseEntity 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 // */ // @ExceptionHandler(JsonProcessingException.class) // protected ResponseEntity 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 // */ // @ExceptionHandler(WnbtRestException.class) // protected final ResponseEntity 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 // */ // @ExceptionHandler(WnbtPosRestException.class) // protected final ResponseEntity 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 // */ // @ExceptionHandler(WnbtTmRestException.class) // protected final ResponseEntity 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 // */ // @ExceptionHandler(Exception.class) // protected final ResponseEntity 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); // } }