Exception handler trumps 404 error handler since Javalin 2.5.0
See original GitHub issueActual behavior (the bug) Since version 2.5.0, when I define an exception handler as well as an error handler for status code 404, a 500 response as created by the exception handler is returned. The error handler does not seem to have any effect.
Expected behavior When I register both an exception handler and an error handler for status code 404, 404 responses are not transformed into 500 responses. This is the behaviour on Javalin 2.4.0 and earlier versions.
To Reproduce Here is a small demo application:
import io.javalin.Javalin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Main {
private static final Logger log = LoggerFactory.getLogger(Main.class);
public static void main(final String[] args) {
final var server = Javalin.create()
.port(8000)
.error(404, ctx -> ctx.result("NOT FOUND!"))
.exception(Exception.class, (e, ctx) -> {
log.error("Exception was thrown", e);
ctx.result("BOOM!");
})
.get("/hello", ctx -> ctx.result("WORLD!"))
.start();
Runtime.getRuntime().addShutdownHook(new Thread(server::stop));
}
}
In 2.4.0, a request to http://localhost:8000/doesnotexist
returns a 404 with the response body NOT FOUND!
.
In 2.5.0, the same request returns a 500 with the response body BOOM!
.
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (7 by maintainers)
Top Results From Across the Web
Exception handler trumps 404 error handler since Javalin 2.5.0
Actual behavior (the bug) Since version 2.5.0, when I define an exception handler as well as an error handler for status code 404, ......
Read more >Trump campaign site's 404 error page takes opportunity to ...
Donald Trump has frequently referred to Mr Biden as “Sleepy Joe Biden”. Commentators have questioned the wisdom of attacking Mr Biden in this ......
Read more >How to handle 404 page not found error properly?
It seems that the API will throw FailingHttpStatusCodeException if you set it up correctly. if the server returns a failing status code AND ......
Read more >CodaLab Worksheets
... Color library draw outline within inside result shown After tab Sketch ... monolithic pillars palaces handling 13th harmonious marriage sculptural ...
Read more >Chapter 8, Text File 1 (515.8Kb) - Knowledge Bank
... accordion xkordixn 1 5.9167 0 0 accost xkcst 1 5.0833 1 2 account xkWnt 117 7 1 2 accountant xkWntNt 2 7...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You’re very welcome. This was a pretty serious bug, so I’ll probably release a new version soon.
Thank you very much for putting out a release with a fix so quickly. You rock! 👏