I will try to do it shortly. Here is the problem I am having when trying to understand Spark filters. I am trying to create a simple application, and one of the things that it should do is to create an error report every time the client is about to see an HTTP error, for example. 404 or 500. Here's what my application looks like:
import static spark.Spark.*; public class MyApp { public static void main(String[] args) { get("/hello", (req, res) -> "{\"status\":\"OK\"}"); after((request, response) -> { if (response.raw().getStatus() == 404) {
For some reason, the response parameter has its status attribute equal to 0 when I check if it is set to 404. The documentation says "after" filters are evaluated after each request and can read the request and read/modify the response , so I have to do it somehow (if only the documents are incorrect).
Basically, I'm trying to catch HTTP errors using the after filter, but when I try to check the response, I don't get what I expect.
Does anyone have an idea what would be another way to do the same or how to make this work?
Thanks.
source share