diff --git a/skr-common/src/main/java/org/skr/common/exception/ErrorInfo.java b/skr-common/src/main/java/org/skr/common/exception/ErrorInfo.java index aa9a1de..da9fe0b 100644 --- a/skr-common/src/main/java/org/skr/common/exception/ErrorInfo.java +++ b/skr-common/src/main/java/org/skr/common/exception/ErrorInfo.java @@ -111,6 +111,7 @@ private static ErrorInfo getOrCopy(@NonNull ErrorInfo target) { } public ErrorInfo exception(Throwable ex) { + if (ex == null) return this; ErrorInfo errorInfo = getOrCopy(this); errorInfo.exception = BaseException.getStackTrace(ex); return errorInfo; diff --git a/skr-common/src/main/java/org/skr/config/GeneralExceptionHandler.java b/skr-common/src/main/java/org/skr/config/GeneralExceptionHandler.java index 5a4dd81..e1af90f 100644 --- a/skr-common/src/main/java/org/skr/config/GeneralExceptionHandler.java +++ b/skr-common/src/main/java/org/skr/config/GeneralExceptionHandler.java @@ -57,7 +57,7 @@ protected ResponseEntity handleExceptionInternal(Exception ex, Object bo if (status.value() == HttpStatus.BAD_REQUEST.value() || status.value() == HttpStatus.NOT_FOUND.value() || status.value() == HttpStatus.METHOD_NOT_ALLOWED.value()) { - respBody = ErrorInfo.BAD_REQUEST.msgArgs(status.value()); + respBody = ErrorInfo.BAD_REQUEST.msgArgs(status.value()).exception(ex); } else { applicationContext.publishEvent(new ErrorOccurredEvent(ex, request)); respBody = Optional.ofNullable(body) @@ -69,37 +69,37 @@ protected ResponseEntity handleExceptionInternal(Exception ex, Object bo @ExceptionHandler(ConfException.class) public ResponseEntity handleException(ConfException ex, WebRequest request) { return handleExceptionInternal(ex, - ex.getErrorInfo(), - new HttpHeaders(), - HttpStatus.INTERNAL_SERVER_ERROR, - request); + ex.getErrorInfo(), + new HttpHeaders(), + HttpStatus.INTERNAL_SERVER_ERROR, + request); } @ExceptionHandler(BizException.class) public ResponseEntity handleException(BizException ex, WebRequest request) { return handleExceptionInternal(ex, - ex.getErrorInfo(), - new HttpHeaders(), - HttpStatus.INTERNAL_SERVER_ERROR, - request); + ex.getErrorInfo(), + new HttpHeaders(), + HttpStatus.INTERNAL_SERVER_ERROR, + request); } @ExceptionHandler(AuthException.class) public ResponseEntity handleException(AuthException ex, WebRequest request) { return handleExceptionInternal(ex, - ex.getErrorInfo(), - new HttpHeaders(), - HttpStatus.UNAUTHORIZED, - request); + ex.getErrorInfo(), + new HttpHeaders(), + HttpStatus.UNAUTHORIZED, + request); } @ExceptionHandler(PermissionException.class) public ResponseEntity handleException(PermissionException ex, WebRequest request) { return handleExceptionInternal(ex, - ex.getErrorInfo(), - new HttpHeaders(), - HttpStatus.FORBIDDEN, - request); + ex.getErrorInfo(), + new HttpHeaders(), + HttpStatus.FORBIDDEN, + request); } @ExceptionHandler(ValidationException.class) @@ -107,28 +107,27 @@ public ResponseEntity handleException(ValidationException ex, WebRequest return handleExceptionInternal(ex, ex.getErrorInfos(), new HttpHeaders(), - HttpStatus.FORBIDDEN, + HttpStatus.BAD_REQUEST, request); } @ExceptionHandler(UnvarnishedFeignException.class) public ResponseEntity handleException(UnvarnishedFeignException ex, WebRequest request) { return handleExceptionInternal(ex, - ex.getErrorInfo(), - new HttpHeaders(), - HttpStatus.valueOf(ex.getResponseStatus()), - request); + ex.getErrorInfo(), + new HttpHeaders(), + HttpStatus.valueOf(ex.getResponseStatus()), + request); } @ExceptionHandler(Exception.class) public ResponseEntity handleUncaughtException(Exception ex, WebRequest request) { log.error(getStackTrace(ex)); return handleExceptionInternal(ex, null, - new HttpHeaders(), - HttpStatus.INTERNAL_SERVER_ERROR, - request); + new HttpHeaders(), + HttpStatus.INTERNAL_SERVER_ERROR, + request); } - }