http-service: set response status to 501 if an exception is encountered

This commit is contained in:
Adam
2017-07-08 12:33:47 -04:00
parent 5a514084c3
commit c690d11840
2 changed files with 12 additions and 2 deletions

View File

@@ -120,7 +120,13 @@ public class Service implements SparkApplication
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);
}
}

View File

@@ -75,7 +75,11 @@ public class SparkServlet extends HttpServlet
FilterChain chain = (req2, resp2) ->
{
// 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);