}
if (blcException.getMessages() != null && !blcException.getMessages().isEmpty()) {
Set<String> keys = blcException.getMessages().keySet();
for (String key : keys) {
ErrorMessageWrapper errorMessageWrapper = (ErrorMessageWrapper) context.getBean(ErrorMessageWrapper.class.getName());
errorMessageWrapper.setMessageKey(resolveClientMessageKey(key));
errorMessageWrapper.setMessage(messageSource.getMessage(key, blcException.getMessages().get(key), key, locale));
errorWrapper.getMessages().add(errorMessageWrapper);
}
} else {
ErrorMessageWrapper errorMessageWrapper = (ErrorMessageWrapper) context.getBean(ErrorMessageWrapper.class.getName());
errorMessageWrapper.setMessageKey(resolveClientMessageKey(BroadleafWebServicesException.UNKNOWN_ERROR));
errorMessageWrapper.setMessage(messageSource.getMessage(BroadleafWebServicesException.UNKNOWN_ERROR, null,
BroadleafWebServicesException.UNKNOWN_ERROR, locale));
errorWrapper.getMessages().add(errorMessageWrapper);
}
} else if (t instanceof WebApplicationException) {
//We will trust that if someone through a WebApplicationException, then they already created the
//response properly.
if (t.getCause() != null) {
LOG.error("An error occured invoking a REST service.", t.getCause());
}
WebApplicationException webAppException = (WebApplicationException) t;
return webAppException.getResponse();
} else {
LOG.error("An error occured invoking a REST service", t);
if (locale == null) {
locale = Locale.getDefault();
}
errorWrapper.setHttpStatusCode(500);
ErrorMessageWrapper errorMessageWrapper = (ErrorMessageWrapper) context.getBean(ErrorMessageWrapper.class.getName());
errorMessageWrapper.setMessageKey(resolveClientMessageKey(BroadleafWebServicesException.UNKNOWN_ERROR));
errorMessageWrapper.setMessage(messageSource.getMessage(BroadleafWebServicesException.UNKNOWN_ERROR, null,
BroadleafWebServicesException.UNKNOWN_ERROR, locale));
errorWrapper.getMessages().add(errorMessageWrapper);
}
return Response.status(resolveResponseStatusCode(t, errorWrapper)).type(mediaType).entity(errorWrapper).build();