Falcon returns HTML on unhandled exceptions
See original GitHub issueWhen 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:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top 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 >
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 Free
Top 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
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.
Awesome, ill check it out. Thanks!