Skip to content

Commit

Permalink
update 40x http error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
hank-cp committed Dec 27, 2023
1 parent 9e799ce commit 2014f87
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected ResponseEntity<Object> 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)
Expand All @@ -69,66 +69,65 @@ protected ResponseEntity<Object> handleExceptionInternal(Exception ex, Object bo
@ExceptionHandler(ConfException.class)
public ResponseEntity<Object> 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<Object> 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<Object> 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<Object> 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)
public ResponseEntity<Object> handleException(ValidationException ex, WebRequest request) {
return handleExceptionInternal(ex,
ex.getErrorInfos(),
new HttpHeaders(),
HttpStatus.FORBIDDEN,
HttpStatus.BAD_REQUEST,
request);
}

@ExceptionHandler(UnvarnishedFeignException.class)
public ResponseEntity<Object> 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<Object> 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);
}



}

0 comments on commit 2014f87

Please sign in to comment.