Added exception marshalling/umarshalling via json using jackson

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/resource-registry@144210 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2017-02-23 16:08:04 +00:00
parent b1e3f5eb34
commit bf27efa315
1 changed files with 12 additions and 4 deletions

View File

@ -18,19 +18,27 @@ public class ResourceRegistryExceptionMapper implements ExceptionMapper<Resource
@Override
public Response toResponse(ResourceRegistryException exception) {
Status status = Status.BAD_REQUEST;
String entity = exception.getMessage();
MediaType mediaType = MediaType.TEXT_PLAIN_TYPE;
if(ERNotFoundException.class.isAssignableFrom(exception.getClass())){
status = Status.NOT_FOUND;
}else if(ERAlreadyPresentException.class.isAssignableFrom(exception.getClass())){
status = Status.FORBIDDEN;
} else {
} else if(exception.getClass() == ResourceRegistryException.class){
status = Status.INTERNAL_SERVER_ERROR;
}
return Response.status(status).entity(entity).type(mediaType).build();
try {
String entity = org.gcube.informationsystem.resourceregistry.api.exceptions.ExceptionMapper.marshal(exception);
MediaType mediaType = MediaType.APPLICATION_JSON_TYPE;
return Response.status(status).entity(entity).type(mediaType).build();
}catch (Exception e) {
String entity = exception.getMessage();
MediaType mediaType = MediaType.TEXT_PLAIN_TYPE;
return Response.status(status).entity(entity).type(mediaType).build();
}
}
}