perwendel / spark

A simple expressive web framework for java. Spark has a kotlin DSL https://github.com/perwendel/spark-kotlin
Apache License 2.0
9.63k stars 1.56k forks source link

Unexpected 404 with exceptionHandler with empty response body #1011

Closed jlorenzen closed 6 years ago

jlorenzen commented 6 years ago

It seems spark will return a 404 when an exception handler does not set the response body. The following should reproduce the issue:

before("/foo", (request, response) -> throw new CustomException());
get("/foo" (request, response) -> "Hello");
exception(CustomException.class (ex, request, response) -> {
    response.status(401);
    response.header("WWW-Authenticate", "Bearer");
    // response.body("");
});

When the line response.body is commented out, hitting that endpoint will result in a 404. When the line is uncommented out, a 401 is returned. It doesn't seem like we should have to set the response body.

tipsy commented 6 years ago

Routes need to return a value (or have a body set), or they will result in a 404. It's known behavior, but it hasn't been changed because of backwards compatibility.

jlorenzen commented 6 years ago

ok thanks @tipsy