forked from Qortal/qortal
Return HTTP 400 code with useful message when a ParamException occurs from API call.
This commit is contained in:
parent
315ebff61d
commit
97142fdde8
@ -10,6 +10,7 @@ import javax.ws.rs.ext.Provider;
|
|||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.glassfish.jersey.server.ParamException;
|
||||||
|
|
||||||
@Provider
|
@Provider
|
||||||
public class ApiExceptionMapper implements ExceptionMapper<RuntimeException> {
|
public class ApiExceptionMapper implements ExceptionMapper<RuntimeException> {
|
||||||
@ -26,6 +27,11 @@ public class ApiExceptionMapper implements ExceptionMapper<RuntimeException> {
|
|||||||
public Response toResponse(RuntimeException e) {
|
public Response toResponse(RuntimeException e) {
|
||||||
LOGGER.info(String.format("Exception %s during API call: %s", e.getClass().getCanonicalName(), request.getRequestURI()));
|
LOGGER.info(String.format("Exception %s during API call: %s", e.getClass().getCanonicalName(), request.getRequestURI()));
|
||||||
|
|
||||||
|
if (e instanceof ParamException) {
|
||||||
|
ParamException pe = (ParamException) e;
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST).entity("Bad parameter \"" + pe.getParameterName() + "\"").build();
|
||||||
|
}
|
||||||
|
|
||||||
if (e instanceof WebApplicationException)
|
if (e instanceof WebApplicationException)
|
||||||
return ((WebApplicationException) e).getResponse();
|
return ((WebApplicationException) e).getResponse();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user