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.

Falcon returns HTML on unhandled exceptions

See original GitHub issue

When an unhandled exception is raised, falcon returns HTML. For a framework that aims to make writing APIs simpler, I would think it should never return HTML unless explicitly configured to do so. We were able to setup an error handler to solve the issue, but should the default behavior be to send either JSON or XML back for unhandled exceptions?

I’m using falcon version 2.0.0

Simple example:

import falcon

class BadEndpoint:

    def on_get(self, req, resp):
        raise AttributeError("oops")

api = falcon.API()
api.add_route('/raise', BadEndpoint())
$ curl http://localhost:8000/raise
<html>
  <head>
    <title>Internal Server Error</title>
  </head>
  <body>
    <h1><p>Internal Server Error</p></h1>

  </body>
</html>

I searched through the issues and didn’t see this mentioned anywhere else.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jmvrbanaccommented, Jun 12, 2019

Thanks for reporting this! This issue is currently due to the fact that we’re currently surfacing uncaught errors to the WSGI server and a number of WSGI servers (such as Gunicorn) return an html error by default. We’re currently investigating a way to deal with this as a part of PR #1527 . If you need an immediate workaround, you can add a custom error handler to your falcon app to handle generic exceptions: https://falcon.readthedocs.io/en/stable/api/api.html#falcon.API.add_error_handler . Hopefully that helps you workaround the issue until we can get a more long-term solution released.

0reactions
jceresinicommented, Nov 4, 2019

Awesome, ill check it out. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to respond with HTTP 500 on any unhandled exception ...
Accepted answer seems to gobble actual HTTPError returned from the application code. ... try: func(*args) except Exception as e: resp.status = falcon.
Read more >
Error Handling — Falcon 3.1.1 documentation
By default, any uncaught exceptions will return an HTTP 500 response and log details of the exception to wsgi.errors . Base Class¶. class...
Read more >
Java Logging Guide Part 2: Advanced Concepts | CrowdStrike
Part two of the Java logging guide will talk about advanced functionalities like exception handling, layouts, and aggregation.
Read more >
Changelog for Falcon 3.0.0
An unhandled exception will no longer be raised to the web server. ... Response.data property now just simply returns the same data object...
Read more >
clang-tidy - bugprone-unhandled-exception-at-new
int *f() noexcept { int *p = new int[1000]; // warning: missing exception handler for allocation failure at 'new' // ... return p;...
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