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.

Error Handler Method in FastAPI

See original GitHub issue

Am trying to migrate a flask code base to FastAPI , what is FastAPI equivalent of the flask code below,

from flask import Flask, url_for, render_template

app = Flask(__name__)

@app.route("/" )
def Index():
    return {"Hello": "World"}

@app.errorhandler(404 )
def page_not_found(e):
    return render_template("404.html")

if __name__ == "__main__":
    app.run(debug=true)

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
HarunMbaabucommented, Feb 18, 2021

Just did.

On Thu, Feb 18, 2021 at 2:54 PM Yagiz Degirmenci notifications@github.com wrote:

You are welcome! If your problem is resolved can you close the issue?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tiangolo/fastapi/issues/2831#issuecomment-781291110, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMGEOORFP3SMBKLLU76AWPTS7T5YDANCNFSM4XZ7J5VA .

1reaction
HarunMbaabucommented, Feb 18, 2021

Thank you, That Worked.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handling Errors - FastAPI
FastAPI has some default exception handlers. These handlers are in charge of returning the default JSON responses when you raise an HTTPException and...
Read more >
3 Ways to Handle Errors in FastAPI That You Need to Know
1. HTTPException #. This function ships with the fastapi module. Therefore, in order to start using it, we just need to import it....
Read more >
The Ultimate FastAPI Tutorial Part 5 - Basic Error Handling
The Ultimate FastAPI Tutorial Part 5 - Basic Error Handling. In part 5 of the FastAPI tutorial, we'll look at basic error handling....
Read more >
Catch `Exception` globally in FastAPI - Stack Overflow
In case you want to capture all unhandled exceptions (internal server error), there's a very simple way of doing it. Documentation
Read more >
How to Add Exception Monitoring to FastAPI - Honeybadger.io
FastAPI is a high-performance web framework for building APIs with Python that has been growing in popularity.
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