added possibility to give a root cause without exception

This commit is contained in:
2018-07-29 14:59:17 +02:00
parent f648cb4090
commit a526fd9e40
2 changed files with 12 additions and 0 deletions

View File

@ -52,6 +52,13 @@ public class APIErrorResponse {
this.message = getLocalizedMessage(apiError, locale); this.message = getLocalizedMessage(apiError, locale);
this.rootCause = th.getMessage(); this.rootCause = th.getMessage();
} }
public APIErrorResponse(APIError apiError, Locale locale, String rootCauseMessage) {
this.status = apiError.getStatus();
this.errorCode = apiError.getErrorCode();
this.message = getLocalizedMessage(apiError, locale);
this.rootCause = rootCauseMessage;
}
public APIErrorResponse(Exception exception, Locale locale) { public APIErrorResponse(Exception exception, Locale locale) {
this.status = Response.Status.INTERNAL_SERVER_ERROR; this.status = Response.Status.INTERNAL_SERVER_ERROR;

View File

@ -29,6 +29,7 @@ public class APIException extends RuntimeException {
public static final String HTTP_HEADER_X_ERROR = "X-Error"; public static final String HTTP_HEADER_X_ERROR = "X-Error";
public static final String HTTP_HEADER_X_ERROR_CODE = "X-Error-Code"; public static final String HTTP_HEADER_X_ERROR_CODE = "X-Error-Code";
public static final String HTTP_HEADER_X_ROOT_CAUSE = "X-Root-Cause"; public static final String HTTP_HEADER_X_ROOT_CAUSE = "X-Root-Cause";
private static final long serialVersionUID = -4356132354448841938L;
private final Response httpResponse; private final Response httpResponse;
@ -39,6 +40,10 @@ public class APIException extends RuntimeException {
public APIException(APIError apiError, Locale locale, Throwable th) { public APIException(APIError apiError, Locale locale, Throwable th) {
httpResponse = createHttpResponse(new APIErrorResponse(apiError, locale, th)); httpResponse = createHttpResponse(new APIErrorResponse(apiError, locale, th));
} }
public APIException(APIError apiError, Locale locale, String rootCause) {
httpResponse = createHttpResponse(new APIErrorResponse(apiError, locale, rootCause));
}
public APIException(Exception exception, Locale locale) { public APIException(Exception exception, Locale locale) {
httpResponse = createHttpResponse(new APIErrorResponse(exception, locale)); httpResponse = createHttpResponse(new APIErrorResponse(exception, locale));