dependency updates

This commit is contained in:
Joern Muehlencord
2021-12-13 22:13:20 +01:00
parent cd2e3b0642
commit 84b8b0545f
23 changed files with 1981 additions and 850 deletions

View File

@ -60,14 +60,14 @@ public class APIErrorResponse {
this.rootCause = rootCauseMessage;
}
public APIErrorResponse(Exception exception, Locale locale) {
public APIErrorResponse(Exception exception) {
this.status = Response.Status.INTERNAL_SERVER_ERROR;
this.errorCode = "0";
this.message = exception.getLocalizedMessage();
this.rootCause = null;
}
public APIErrorResponse(Exception exception, Locale locale, Throwable th) {
public APIErrorResponse(Exception exception, Throwable th) {
this.status = Response.Status.INTERNAL_SERVER_ERROR;
this.errorCode = "0";
this.message = exception.getLocalizedMessage();

View File

@ -31,7 +31,7 @@ public class APIException extends RuntimeException {
public static final String HTTP_HEADER_X_ROOT_CAUSE = "X-Root-Cause";
private static final long serialVersionUID = -4356132354448841938L;
private final Response httpResponse;
private final transient Response httpResponse;
public APIException(APIError apiError, Locale locale) {
httpResponse = createHttpResponse(new APIErrorResponse(apiError, locale));
@ -49,8 +49,8 @@ public class APIException extends RuntimeException {
httpResponse = createHttpResponse(new APIErrorResponse(apiError, new Locale(locale), rootCause));
}
public APIException(Exception exception, Locale locale) {
httpResponse = createHttpResponse(new APIErrorResponse(exception, locale));
public APIException(Exception exception) {
httpResponse = createHttpResponse(new APIErrorResponse(exception));
}
public Response getHttpResponse() {

View File

@ -1,4 +1,4 @@
/*
/*
* Copyright 2019 Joern Muehlencord (joern@muehlencord.de).
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -25,46 +25,41 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author Joern Muehlencord (joern@muehlencord.de)
*/
public class APIExceptionInterceptor {
private static final Logger LOGGER = LoggerFactory.getLogger(APIExceptionInterceptor.class);
private static final Logger logger = LoggerFactory.getLogger(APIExceptionInterceptor.class);
@Inject
Locale locale;
@Inject
Locale locale;
@AroundInvoke
public Object handleException(InvocationContext context) {
Object proceedResponse;
try {
// continue to execute context
// if an exception is thrown during processing, this is passed in to the catch block below
proceedResponse = context.proceed();
} catch (Exception ex) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(ex.getMessage());
LOGGER.debug("Detailed stacktrace", new Object[]{ex});
}
Response errorResponse;
if (ex instanceof APIException) {
errorResponse = ((APIException) ex).getHttpResponse();
} else if (ex.getCause() instanceof APIException) {
errorResponse = ((APIException) ex.getCause()).getHttpResponse();
} else if (ex instanceof ConstraintViolationException) {
// this exception is handled via the ConstraintViolationMapper
throw (ConstraintViolationException) ex;
} else if (ex.getCause() instanceof ConstraintViolationException) {
// this exception is handled via the ConstraintViolationMapper
throw (ConstraintViolationException) ex.getCause();
} else {
errorResponse = new APIException(ex, locale).getHttpResponse();
}
return errorResponse;
}
return proceedResponse;
@AroundInvoke
public Object handleException(InvocationContext context) {
Object proceedResponse;
try {
// continue to execute context
// if an exception is thrown during processing, this is passed in to the catch block below
proceedResponse = context.proceed();
} catch (Exception ex) {
logger.debug(ex.getMessage(), ex);
Response errorResponse;
if (ex instanceof APIException) {
errorResponse = ((APIException) ex).getHttpResponse();
} else if (ex.getCause() instanceof APIException) {
errorResponse = ((APIException) ex.getCause()).getHttpResponse();
} else if (ex instanceof ConstraintViolationException) {
// this exception is handled via the ConstraintViolationMapper
throw (ConstraintViolationException) ex;
} else if (ex.getCause() instanceof ConstraintViolationException) {
// this exception is handled via the ConstraintViolationMapper
throw (ConstraintViolationException) ex.getCause();
} else {
errorResponse = new APIException(ex).getHttpResponse();
}
return errorResponse;
}
return proceedResponse;
}
}