Skip to content

Flask's abort(404) does not work with Zero #133

Open
@Hubro

Description

@Hubro

I've made a Python API file for fetching a resource. If the resource doesn't exist, I want to return "404 Not Found". I have tried Flask's abort(404), but the NotFound error is caught at some point and I get a TypeError instead, resulting in a 500 Server Error from Zero. Here is the stack trace:

werkzeug.exceptions.NotFound: 404 Not Found: The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.
[2020-06-05 20:40:01,549] ERROR in app: Exception on /video/foobar/ [GET]
Traceback (most recent call last):
  File "/home/tomas/.local/lib/python3.8/site-packages/flask/app.py", line 2446, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/tomas/.local/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
    return self.finalize_request(rv)
  File "/home/tomas/.local/lib/python3.8/site-packages/flask/app.py", line 1967, in finalize_request
    response = self.make_response(rv)
  File "/home/tomas/.local/lib/python3.8/site-packages/flask/app.py", line 2096, in make_response
    raise TypeError(
TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement.

Is this a bug? Or is there a different way to do it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions