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:
parent
b1e3f5eb34
commit
bf27efa315
|
@ -18,19 +18,27 @@ public class ResourceRegistryExceptionMapper implements ExceptionMapper<Resource
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response toResponse(ResourceRegistryException exception) {
|
public Response toResponse(ResourceRegistryException exception) {
|
||||||
|
|
||||||
Status status = Status.BAD_REQUEST;
|
Status status = Status.BAD_REQUEST;
|
||||||
String entity = exception.getMessage();
|
|
||||||
MediaType mediaType = MediaType.TEXT_PLAIN_TYPE;
|
|
||||||
|
|
||||||
if(ERNotFoundException.class.isAssignableFrom(exception.getClass())){
|
if(ERNotFoundException.class.isAssignableFrom(exception.getClass())){
|
||||||
status = Status.NOT_FOUND;
|
status = Status.NOT_FOUND;
|
||||||
}else if(ERAlreadyPresentException.class.isAssignableFrom(exception.getClass())){
|
}else if(ERAlreadyPresentException.class.isAssignableFrom(exception.getClass())){
|
||||||
status = Status.FORBIDDEN;
|
status = Status.FORBIDDEN;
|
||||||
} else {
|
} else if(exception.getClass() == ResourceRegistryException.class){
|
||||||
status = Status.INTERNAL_SERVER_ERROR;
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue