Implement ExceptionMapper (2.1.3.1)
This commit is contained in:
parent
89467e49cb
commit
1e96417a3f
@ -32,8 +32,8 @@ public interface ITripServiceResource {
|
||||
Response addStop(@PathParam("id") Long tripId, @FormParam("locationId") Long locationId) throws InvalidTripException, EntityNotFoundException;
|
||||
|
||||
@DELETE
|
||||
@Path("{id}/stops")
|
||||
Response removeStop(@PathParam("id") Long tripId, @FormParam("locationId") Long locationId) throws InvalidTripException, EntityNotFoundException;
|
||||
@Path("{id}/stops/{locationId}")
|
||||
Response removeStop(@PathParam("id") Long tripId, @PathParam("locationId") Long locationId) throws InvalidTripException, EntityNotFoundException;
|
||||
|
||||
@POST
|
||||
@Path("{id}/match")
|
||||
|
||||
@ -3,13 +3,13 @@ package dst.ass2.service.trip.impl;
|
||||
import dst.ass2.service.api.trip.*;
|
||||
import dst.ass2.service.api.trip.rest.ITripServiceResource;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
|
||||
@Provider
|
||||
public class TripServiceResource implements ITripServiceResource {
|
||||
@Resource
|
||||
@Inject
|
||||
private ITripService tripService;
|
||||
|
||||
@Override
|
||||
|
||||
@ -0,0 +1,30 @@
|
||||
package dst.ass2.service.trip.impl;
|
||||
|
||||
import dst.ass2.service.api.trip.DriverNotAvailableException;
|
||||
import dst.ass2.service.api.trip.EntityNotFoundException;
|
||||
import dst.ass2.service.api.trip.InvalidTripException;
|
||||
|
||||
import javax.ws.rs.NotAllowedException;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.ext.ExceptionMapper;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
|
||||
@Provider
|
||||
public class TripServiceResourceExceptionMapper implements ExceptionMapper<Throwable> {
|
||||
@Override
|
||||
public Response toResponse(Throwable exception) {
|
||||
if (exception instanceof EntityNotFoundException) {
|
||||
return Response.status(Response.Status.NOT_FOUND).entity(exception.getMessage()).build();
|
||||
} else if (exception instanceof IllegalStateException) {
|
||||
return Response.status(Response.Status.CONFLICT).entity(exception.getMessage()).build();
|
||||
} else if (exception instanceof InvalidTripException) {
|
||||
return Response.status(Response.Status.CONFLICT).entity(exception.getMessage()).build();
|
||||
} else if (exception instanceof DriverNotAvailableException) {
|
||||
return Response.status(Response.Status.CONFLICT).entity(exception.getMessage()).build();
|
||||
} else if (exception instanceof NotAllowedException) {
|
||||
return Response.status(Response.Status.METHOD_NOT_ALLOWED).entity(exception.getMessage()).build();
|
||||
}
|
||||
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(exception.getMessage()).build();
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user