diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-12-20 14:40:15 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-12-20 14:40:15 +1300 |
commit | 3eff91673944f202e0aebe20faa925011568b685 (patch) | |
tree | 8b3db829d90ca73faa132463eff8661a7335936f /src/org/traccar/api/ResourceErrorHandler.java | |
parent | 4d29679dec4508d28af7651cdfd130e5a218b387 (diff) | |
download | trackermap-server-3eff91673944f202e0aebe20faa925011568b685.tar.gz trackermap-server-3eff91673944f202e0aebe20faa925011568b685.tar.bz2 trackermap-server-3eff91673944f202e0aebe20faa925011568b685.zip |
Check permissions for REST API calls
Diffstat (limited to 'src/org/traccar/api/ResourceErrorHandler.java')
-rw-r--r-- | src/org/traccar/api/ResourceErrorHandler.java | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/org/traccar/api/ResourceErrorHandler.java b/src/org/traccar/api/ResourceErrorHandler.java index e2f4dce10..be63aad09 100644 --- a/src/org/traccar/api/ResourceErrorHandler.java +++ b/src/org/traccar/api/ResourceErrorHandler.java @@ -23,21 +23,21 @@ import javax.ws.rs.ext.ExceptionMapper; import java.util.HashMap; import java.util.Map; -public class ResourceErrorHandler implements ExceptionMapper<WebApplicationException> { +public class ResourceErrorHandler implements ExceptionMapper<Exception> { private static final String KEY_MESSAGE = "message"; private static final String KEY_DETAILS = "details"; @Override - public Response toResponse(WebApplicationException e) { + public Response toResponse(Exception e) { Map<String, String> error = new HashMap<>(); - Throwable cause = e.getCause(); - if (cause != null) { - error.put(KEY_MESSAGE, cause.getMessage()); - error.put(KEY_DETAILS, Log.exceptionStack(cause)); - return Response.status(Response.Status.BAD_REQUEST).entity(error).build(); + if (e instanceof WebApplicationException) { + WebApplicationException webApplicationException = (WebApplicationException) e; + return Response.status(webApplicationException.getResponse().getStatus()).entity(error).build(); } else { - return Response.status(e.getResponse().getStatus()).entity(error).build(); + error.put(KEY_MESSAGE, e.getMessage()); + error.put(KEY_DETAILS, Log.exceptionStack(e)); + return Response.status(Response.Status.BAD_REQUEST).entity(error).build(); } } |