http-service: set response status to 501 if an exception is encountered
This commit is contained in:
@@ -120,7 +120,13 @@ public class Service implements SparkApplication
|
|||||||
get("/:id/price/:time", item::getPrice, transformer);
|
get("/:id/price/:time", item::getPrice, transformer);
|
||||||
});
|
});
|
||||||
|
|
||||||
exception(Exception.class, (exception, request, response) -> logger.warn(null, exception));
|
exception(Exception.class, this::handleException);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleException(Exception ex, Request request, Response response)
|
||||||
|
{
|
||||||
|
logger.warn("error processing request", ex);
|
||||||
|
response.status(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,11 @@ public class SparkServlet extends HttpServlet
|
|||||||
FilterChain chain = (req2, resp2) ->
|
FilterChain chain = (req2, resp2) ->
|
||||||
{
|
{
|
||||||
// Called if the matcherFilter ends up not setting a body
|
// Called if the matcherFilter ends up not setting a body
|
||||||
resp.setStatus(404);
|
// something might have changed changed the error from 200
|
||||||
|
if (resp.getStatus() == 200)
|
||||||
|
{
|
||||||
|
resp.setStatus(404);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
matcherFilter.doFilter(requestWrapper, resp, chain);
|
matcherFilter.doFilter(requestWrapper, resp, chain);
|
||||||
|
|||||||
Reference in New Issue
Block a user