? getSyncopeClientCompositeExceptionResponse(sce.asComposite())
: getSyncopeClientExceptionResponse(sce);
} else if (ex instanceof WebApplicationException) {
Response response = ((WebApplicationException) ex).getResponse();
ErrorTO error = new ErrorTO();
error.setStatus(response.getStatus());
error.setType(ClientExceptionType.Unknown);
error.getElements().add(getExMessage(ex));
builder = JAXRSUtils.fromResponse(response).entity(error);
} else if (ex instanceof AccessDeniedException) {
builder = Response.status(Response.Status.UNAUTHORIZED).
header(HttpHeaders.WWW_AUTHENTICATE, BASIC_REALM_UNAUTHORIZED);
} else if (ex instanceof UnauthorizedRoleException) {
builder = builder(Response.Status.UNAUTHORIZED, ClientExceptionType.UnauthorizedRole, getExMessage(ex));
} else if (ex instanceof EntityExistsException) {
builder = builder(Response.Status.CONFLICT, ClientExceptionType.EntityExists, getExMessage(ex));
} else if (ex instanceof DataIntegrityViolationException) {
builder = builder(Response.Status.CONFLICT, ClientExceptionType.DataIntegrityViolation, getExMessage(ex));
} else {
builder = processNotFoundExceptions(ex);
if (builder == null) {
builder = processInvalidEntityExceptions(ex);
if (builder == null) {
builder = processBadRequestExceptions(ex);
}
// process JAX-RS validation errors
if (builder == null && ex instanceof ValidationException) {
builder = JAXRSUtils.fromResponse(validationEM.toResponse((ValidationException) ex)).
header(RESTHeaders.ERROR_CODE, ClientExceptionType.RESTValidation.getHeaderValue()).
header(RESTHeaders.ERROR_INFO,
ClientExceptionType.RESTValidation.getInfoHeaderValue(getExMessage(ex)));
ErrorTO error = new ErrorTO();
error.setStatus(ClientExceptionType.RESTValidation.getResponseStatus().getStatusCode());
error.setType(ClientExceptionType.RESTValidation);
error.getElements().add(getExMessage(ex));
builder.entity(error);
}
// ...or just report as InternalServerError
if (builder == null) {
builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR).
header(RESTHeaders.ERROR_INFO,
ClientExceptionType.Unknown.getInfoHeaderValue(getExMessage(ex)));
ErrorTO error = new ErrorTO();
error.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
error.setType(ClientExceptionType.Unknown);
error.getElements().add(getExMessage(ex));
builder.entity(error);
}
}
}