fix: API 에러 처리 fix

dev
gitea-관리자 1 year ago
parent a352bbfc69
commit c0689d5f1b

@ -269,28 +269,26 @@ log.info("@@@@@@@@@@@@@@@@@로깅 start : [\n{}\n]",MDC.getCopyOfContextMap());
log.info("~~~~~~~~~~~~~~~~~~~~~~~>>>>{}", MDC.get(REQUEST_TRACE_ID));
if(Checks.isEmpty(MDC.get(REQUEST_TRACE_ID))) return;
Map<String,Object> map = ErrorParse.extractError(e);
ApiResponseDTO dto = ErrorParse.extractError(e);
loggingService.modifyLogging(
LoggingDTO
.builder()
.requestId(MDC.get(REQUEST_TRACE_ID))
.success("false")
.response(JsonUtils.toJson(ApiResponseDTO.error(String.valueOf(map.get(CODE)), String.valueOf(map.get(MESSAGE)), (HttpStatus)map.get("httpStatus"))))
.message(String.valueOf(map.get(MESSAGE)))
.response(JsonUtils.toJson(dto))
.message(dto.getMessage())
.build());
//FIXME :: slack webhook log push
if(isSlackEnabled){
if(RequestContextHolder.getRequestAttributes() != null) {
slackWebhookPush.sendSlackAlertLog(
String.format("[%s]%s(%s)", MDC.get(REQUEST_TRACE_ID), String.valueOf(map.get(CODE)),
String.valueOf(map.get(MESSAGE))),
String.format("[%s]%s(%s)", MDC.get(REQUEST_TRACE_ID), dto.getCode(), dto.getMessage()),
((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest());
}else{
slackWebhookPush.sendSlackAlertLog(
String.format("[%s]%s(%s)", MDC.get(REQUEST_TRACE_ID), String.valueOf(map.get(CODE)),
String.valueOf(map.get(MESSAGE))),
String.format("[%s]%s(%s)", MDC.get(REQUEST_TRACE_ID), dto.getCode(), dto.getMessage()),
MDC.get("uri"),
"batch call");
}

@ -39,11 +39,12 @@ contract:
ci: /digital/niceid/cert/v1.0/ipin/addinfo/ci
kt:
dummy: true
# vpn 사용전
host: http://172.16.0.13:10210/ONLWeb
# vpn 사용
# host: http://211.43.10.163:10210/ONLWeb
# host: http://172.16.0.13:10210/ONLWeb
# 공인 IP
host: http://211.43.10.163:10210/ONLWeb
# 운영
#host: http://172.16.1.182:10210/ONLWeb
# signgu-code: 11000
# ffnlg-code: 11
api:
generate-token: /oauth/token
before-send: /api/message/before/send

@ -227,28 +227,26 @@ log.info("@@@@@@@@@@@@@@@@@로깅 start : [\n{}\n]",MDC.getCopyOfContextMap());
log.info("~~~~~~~~~~~~~~~~~~~~~~~>>>>{}", MDC.get(REQUEST_TRACE_ID));
if(Checks.isEmpty(MDC.get(REQUEST_TRACE_ID))) return;
Map<String,Object> map = ErrorParse.extractError(e);
ApiResponseDTO dto = ErrorParse.extractError(e);
loggingService.modifyLogging(
LoggingDTO
.builder()
.requestId(MDC.get(REQUEST_TRACE_ID))
.success("false")
.response(JsonUtils.toJson(ApiResponseDTO.error(String.valueOf(map.get(CODE)), String.valueOf(map.get(MESSAGE)), (HttpStatus)map.get("httpStatus"))))
.message(String.valueOf(map.get(MESSAGE)))
.response(JsonUtils.toJson(dto))
.message(dto.getMessage())
.build());
//FIXME :: slack webhook log push
if(isSlackEnabled){
if(RequestContextHolder.getRequestAttributes() != null) {
slackWebhookPush.sendSlackAlertLog(
String.format("[%s]%s(%s)", MDC.get(REQUEST_TRACE_ID), String.valueOf(map.get(CODE)),
String.valueOf(map.get(MESSAGE))),
String.format("[%s]%s(%s)", MDC.get(REQUEST_TRACE_ID), dto.getCode(), dto.getMessage()),
((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest());
}else{
slackWebhookPush.sendSlackAlertLog(
String.format("[%s]%s(%s)", MDC.get(REQUEST_TRACE_ID), String.valueOf(map.get(CODE)),
String.valueOf(map.get(MESSAGE))),
String.format("[%s]%s(%s)", MDC.get(REQUEST_TRACE_ID), dto.getCode(), dto.getMessage()),
MDC.get("uri"),
"batch call");
}

@ -1,33 +1,31 @@
package kr.xit.core.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonRootName;
import com.google.gson.GsonBuilder;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import org.apache.commons.lang.StringUtils;
import org.egovframe.rte.ptl.mvc.tags.ui.pagination.PaginationInfo;
import org.springframework.http.HttpStatus;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.validation.ObjectError;
import com.google.gson.GsonBuilder;
import io.swagger.v3.oas.annotations.media.Schema;
import kr.xit.core.consts.ErrorCode;
import kr.xit.core.exception.BizRuntimeException;
import kr.xit.core.support.utils.Checks;
import kr.xit.core.support.utils.ConvertHelper;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.egovframe.rte.ptl.mvc.tags.ui.pagination.PaginationInfo;
import org.springframework.http.HttpStatus;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.validation.ObjectError;
/**
* <pre>
@ -46,7 +44,11 @@ import lombok.Setter;
@Schema(name = "ApiResponseDTO", description = "Restful API 결과")
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ApiResponseDTO<T> implements Serializable {
@AllArgsConstructor
@Builder
@JsonRootName("result")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ApiResponseDTO<T> implements IApiResponse {
private static final String FAIL_STATUS = "fail";
private static final String ERROR_STATUS = "error";

@ -1,12 +1,11 @@
package kr.xit.core.model;
import javax.validation.constraints.Size;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import javax.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
@ -26,10 +25,11 @@ import lombok.experimental.SuperBuilder;
* </pre>
*/
@Schema(name = "ErrorDTO", description = "에러 DTO")
@Data
@Getter
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ErrorDTO implements IApiResponse {
/**
* (max:40)

@ -4,15 +4,17 @@ import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.concurrent.CompletionException;
import javax.validation.ConstraintViolationException;
import kr.xit.core.consts.ErrorCode;
import kr.xit.core.exception.BizRuntimeException;
import kr.xit.core.model.ApiResponseDTO;
import kr.xit.core.spring.util.error.ErrorParse;
import kr.xit.core.support.utils.Checks;
import lombok.extern.slf4j.Slf4j;
import org.egovframe.rte.fdl.cmmn.exception.EgovBizException;
import org.slf4j.MDC;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.bind.MethodArgumentNotValidException;
@ -22,13 +24,6 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
import kr.xit.core.consts.ErrorCode;
import kr.xit.core.model.ApiResponseDTO;
import kr.xit.core.exception.BizRuntimeException;
import kr.xit.core.spring.util.error.ErrorParse;
import kr.xit.core.support.utils.Checks;
import lombok.extern.slf4j.Slf4j;
/**
* <pre>
* description : ExceptionHandlerFilter(Filter )
@ -204,7 +199,6 @@ public class CustomRestExceptionHandler extends ResponseEntityExceptionHandler {
private ApiResponseDTO sendError(Throwable e) {
Map<String,Object> map = ErrorParse.extractError(Checks.checkVal(e.getCause(), e));
return ApiResponseDTO.error(String.valueOf(map.get("code")), String.valueOf(map.get("message")), (HttpStatus)map.get("httpStatus"));
return ErrorParse.extractError(Checks.checkVal(e.getCause(), e));
}
}

@ -154,8 +154,7 @@ public class ApiWebClientUtil {
public <T> ApiResponseDTO<T> sendError(final Throwable e) {
Map<String,Object> map = ErrorParse.extractError(e.getCause());
return ApiResponseDTO.error(String.valueOf(map.get("code")), String.valueOf(map.get("message")), (HttpStatus)map.get("httpStatus"));
return ErrorParse.extractError(e.getCause());
}
private URI createUrl(final String endPoint, final String... value) {

@ -1,23 +1,19 @@
package kr.xit.core.spring.util.error;
import java.util.HashMap;
import java.util.Map;
import io.netty.channel.ConnectTimeoutException;
import io.netty.handler.timeout.ReadTimeoutException;
import java.util.Objects;
import java.util.concurrent.ExecutionException;
import kr.xit.core.exception.BizRuntimeException;
import kr.xit.core.model.ApiResponseDTO;
import kr.xit.core.model.ErrorDTO;
import kr.xit.core.support.utils.Checks;
import kr.xit.core.support.utils.JsonUtils;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatus;
import org.springframework.web.reactive.function.client.WebClientRequestException;
import io.netty.channel.ConnectTimeoutException;
import io.netty.handler.timeout.ReadTimeoutException;
import kr.xit.core.model.ErrorDTO;
import kr.xit.core.support.utils.Checks;
import kr.xit.core.support.utils.JsonUtils;
/**
* <pre>
* description :
@ -35,7 +31,7 @@ import kr.xit.core.support.utils.JsonUtils;
*/
public class ErrorParse {
public static Map<String,Object> extractError(final Throwable e){
public static ApiResponseDTO extractError(final Throwable e){
String errCode = String.valueOf(HttpStatus.INTERNAL_SERVER_ERROR.value());
String message = Checks.isNotNull(e) ? e.getLocalizedMessage() : StringUtils.EMPTY;
HttpStatus httpStatus = null;
@ -93,15 +89,11 @@ public class ErrorParse {
}
@NotNull
private static Map<String, Object> getStringObjectMap(String errCode, String message, HttpStatus httpStatus) {
Map<String, Object> errorMap = new HashMap<>();
errorMap.put("code", errCode);
errorMap.put("message", message);
errorMap.put("httpStatus", httpStatus);
return errorMap;
private static ApiResponseDTO getStringObjectMap(String errCode, String message, HttpStatus httpStatus) {
return ApiResponseDTO.error(errCode, message, httpStatus);
}
private static Map<String, Object> getTimeoutException(){
private static ApiResponseDTO getTimeoutException(){
return getStringObjectMap(
String.valueOf(HttpStatus.REQUEST_TIMEOUT.value()),
HttpStatus.REQUEST_TIMEOUT.getReasonPhrase(),

Loading…
Cancel
Save