question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exception handler trumps 404 error handler since Javalin 2.5.0

See original GitHub issue

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, 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:closed
  • Created 5 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
tipsycommented, Jan 16, 2019

You’re very welcome. This was a pretty serious bug, so I’ll probably release a new version soon.

2reactions
dwestheidecommented, Jan 17, 2019

Thank you very much for putting out a release with a fix so quickly. You rock! 👏

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found