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

@ -53,6 +53,13 @@ public class APIErrorResponse {
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) {
this.status = Response.Status.INTERNAL_SERVER_ERROR;
this.errorCode = "0";

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_CODE = "X-Error-Code";
public static final String HTTP_HEADER_X_ROOT_CAUSE = "X-Root-Cause";
private static final long serialVersionUID = -4356132354448841938L;
private final Response httpResponse;
@ -40,6 +41,10 @@ public class APIException extends RuntimeException {
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) {
httpResponse = createHttpResponse(new APIErrorResponse(exception, locale));
}