private void setHttpStatus(Throwable ex, GenericException exception) { if (ex instanceof WebApplicationException) { exception.setStatus(((WebApplicationException) ex).getResponse().getStatus()); } else { exception.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); } }
public Response toResponse(Throwable ex) { logger.error(ex.getMessage(), ex); GenericException exception; if (ex instanceof ApplicationException) { exception = GenericException.from((ApplicationException) ex); } else { exception = new GenericException(); setHttpStatus(ex, exception); exception.setCode(1009); exception.setTittle(ex.getMessage()); exception.setDetail(ex.toString()); exception.setLink(""); } Map<String, List<GenericException>> exMap = new HashMap<>(); exMap.put("errors", Lists.newArrayList(exception)); return Response.status(exception.getStatus()) .entity(exMap) .type(MediaType.APPLICATION_JSON) .build(); }