This Is How You Do PROPER Exception Handling With FastAPI

preview_player
Показать описание
Getting a cryptic error message while using a website? Well, this is probably because custom errors were not implemented. In this video, I’ll show you how to create custom exceptions for a FastAPI application.

🎓 Courses:

👍 If you enjoyed this content, give this video a like. If you want to watch more of my upcoming videos, consider subscribing to my channel!

Social channels:

👀 Code reviewers:
- Yoriz
- Ryan Laursen
- Dale Hagglund
- Kit Hygh
- Alexander Milden
- Bean

🔖 Chapters:
0:00 Intro
0:49 Custom Exceptions
1:21 How to create custom exception classes
2:49 Exception handlers
5:03 Final Thoughts
5:38 Outro

#arjancodes #softwaredesign #python

DISCLAIMER - The links in this description might be affiliate links. If you purchase a product or service through one of those links, I may receive a small commission. There is no additional charge to you. Thanks for supporting my channel so I can continue to provide you with free content each week!
Рекомендации по теме
Комментарии
Автор

I'm a simple man; I see a new ArjanCodes video on backend engineering in python, I like.

milandean
Автор

Great stuff here on exception handling in FastAPI! One thing I always do is make the response from the exception handling fairly generic since it is returned to the user and instead log the critical exception that is being thrown. This allows you to be able to debug without accidentally giving the user unnecessary information! Great video 🙂

codingwithroby
Автор

It's a huge slap to my impostor syndrome when I watch your videos and you describe something I've always done as the norm

badbad_
Автор

been doing some research on this topic the last two days. Thank you

richmondnyamekye
Автор

Interesting approach! The FastAPI content is very good, I hope it will soon be the most used framework in Python because it is great.

diegol_
Автор

Great info. I am curious how you did the logging and what the output looks like. I tried using a root logger using logging/Logger but had issues. I am currently using a file and stream handler (watched another video on this), but the module names are not logging like it does when using a root logger without uvicorn/fastapi.

tascsolutions
Автор

Great video! Any examples on how to do error skipping?

therollingambit
Автор

Coming from a Node.js background, I have a question: why didn't you use try-except for exception handling?

GTX-crob
Автор

Why did you extend from fastapi error class: htttpexception ?

drac
Автор

Should not standard http/s error messages returned? Like a 404 error instead an entity not found error, a 500 error instead a service error. Are you not reinventing the wheel?

christiannovak
Автор

How important is it do create custom exceptions and not just use custom Base exception? By passing message and name, isnt it enough to use a single custom exception?

rain-er
Автор

I Do disagree that raising exceptions as early as possible is good, as it can lead to consumers of your code, catching and adapting to errors.
Of course if you are sure you won't need to catch your own errors, fine, it's quite pythonic.

LewisCowles
Автор

Invalid token is not an exeption. it happens very frequently and handling path is well konwn. Same goes for existing database entries etc.
Exepion is something exepctional as it says: database connection issue, external service being down, hard disk drive failure.

Python - like "catch them up" is just dumb.

hunkonator