Тёмный

This Is How You Do PROPER Exception Handling With FastAPI 

ArjanCodes
Подписаться 239 тыс.
Просмотров 15 тыс.
50% 1

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.
💡 Get my FREE 7-step guide to help you consistently design great software: arjancodes.com/designguide.
🔥 GitHub Repository: git.arjan.codes/2024/tuesday_...
💻 ArjanCodes Blog: www.arjancodes.com/blog
✍🏻 Take a quiz on this topic: www.learntail.com/quiz/zrudva
Try Learntail for FREE ➡️ www.learntail.com/
🎓 Courses:
The Software Designer Mindset: www.arjancodes.com/mindset
The Software Architect Mindset: Pre-register now! www.arjancodes.com/architect
Next Level Python: Become a Python Expert: www.arjancodes.com/next-level...
The 30-Day Design Challenge: www.arjancodes.com/30ddc
🛒 GEAR & RECOMMENDED BOOKS: kit.co/arjancodes.
👍 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:
💬 Discord: discord.arjan.codes
🐦Twitter: / arjancodes
🌍LinkedIn: / arjancodes
🕵Facebook: / arjancodes
📱Instagram: / arjancodes
♪ Tiktok: / arjancodes
👀 Code reviewers:
- Yoriz
- Ryan Laursen
- Dale Hagglund
- Kit Hygh
- Alexander Milden
- Bean
🎥 Video edited by Mark Bacskai: / bacskaimark
🔖 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!

Опубликовано:

 

27 июн 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 21   
@ArjanCodes
@ArjanCodes 2 месяца назад
💡 Get my FREE 7-step guide to help you consistently design great software: arjancodes.com/designguide.
@milandean
@milandean 2 месяца назад
I'm a simple man; I see a new ArjanCodes video on backend engineering in python, I like.
@codingwithroby
@codingwithroby 2 месяца назад
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 🙂
@badbad_
@badbad_ 2 месяца назад
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
@ArjanCodes
@ArjanCodes 2 месяца назад
Glad to hear! You should trust your skill :)
@richmondnyamekye9889
@richmondnyamekye9889 2 месяца назад
been doing some research on this topic the last two days. Thank you
@ArjanCodes
@ArjanCodes 2 месяца назад
Glad this helped!
@diegol_116
@diegol_116 2 месяца назад
Interesting approach! The FastAPI content is very good, I hope it will soon be the most used framework in Python because it is great.
@tascsolutions6483
@tascsolutions6483 2 месяца назад
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.
@therollingambit5222
@therollingambit5222 2 месяца назад
Great video! Any examples on how to do error skipping?
@drac8854
@drac8854 2 месяца назад
Why did you extend from fastapi error class: htttpexception ?
@christiannovak3204
@christiannovak3204 2 месяца назад
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?
@frantisekcastek174
@frantisekcastek174 2 месяца назад
this was nice! when is next Tuesday 😁
@sany2k8
@sany2k8 2 месяца назад
After 6 more days 😂
@genomexp
@genomexp 2 месяца назад
C U then :)
@rain-er6537
@rain-er6537 2 месяца назад
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?
@aflous
@aflous 2 месяца назад
Creating custom exceptions is more than just about passing a message or an identifier, it involves defining a clear and structured error handling strategy that enhances the maintainability and readability of your code, facilitates granular control over different error types in complex applications, and allows for sophisticated control flow mechanisms
@frantisekcastek174
@frantisekcastek174 2 месяца назад
I believe this depends on you or the complexity of the project respectively. You can start simple and when you see that you are doubling too much code, you refactor.
@LewisCowles
@LewisCowles 2 месяца назад
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.
@hunkonator
@hunkonator 2 месяца назад
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.
@youtubeenjoyer1743
@youtubeenjoyer1743 Месяц назад
Python is a product of its time. Back then the hype was OOP and Exceptions. Exceptions in python are used like implicit union typed return values. Maybe it’s a good fit for an interpreted language.
Далее
Rust Handles Errors Way Better Than Python
17:48
Просмотров 16 тыс.
How to Use FastAPI: A Detailed Python Tutorial
20:38
Просмотров 214 тыс.
The Ultimate Guide to Writing Classes in Python
25:39
Просмотров 106 тыс.
Logging in FastAPI Apps / Writing a FastAPI Middleware
31:01
How FastAPI Handles Requests Behind the Scenes
5:09
Просмотров 13 тыс.
Protocols vs ABCs in Python - When to Use Which One?
15:31
Python Logging: How to Write Logs Like a Pro!
11:02
Просмотров 155 тыс.
Why You Should Use Pydantic in 2024 | Tutorial
13:56
Просмотров 61 тыс.
Dependency INVERSION vs Dependency INJECTION in Python
17:51