正在加载视频...
视频加载失败
Stop writing Try Catch Blocks in your Express.js routes.
28,056 次观看 • 10 个月前 •via X (Twitter)
24 条评论

there is a better way...

👏🏻

It's kind of useless. You just create a custom error type holding the status and you do a middleware at the end handling them. You don't need to wrap every handler/controller with that.

Error handling middleware is a cleaner approach 🤷♂️

What the fuck language is this?

So in spring boot world we have something called controller advice We throw the errors and write custom error handlers just once...

It would be good if we can send a custom error msg also so that would make it more reusable i guess. I love these short form videos. Keep making it 🙌

that sounds like solid advice

Very well explained sir

Haan hitesh sir ne Samjha diya backend series main

what is we need to send custom error for specific failures like failing to execute db-queries . its i think its we are writting same just giving fuction a wrapper of try catch

this is actually something which everyone should follow while working on the project

The first thing to stop is express js

The only issue I have with this is, sometimes you might want to handle errors differently for different routes. The use of closure is smart, Welldone 👏

Just migrate to express v5 and you are good to go. No need for custom implementatin.

a better way to do in express!

Gd

can you pls help those of us who dont understand indian with english translation on youtube videos been wanting to watch the system design tutorial but i just cant undersatnd what you saying

Ye to @Hiteshdotcom ki chai aur backend me seekh liya tha

This not solve the problem... you still using try catch

A more flexible way to achieve that.

Ayu dark theme ?

Why not use express-async-errors?

Been using this template for a while now, asyncHandlers, ApiError and ApiResponse as utils, boosted my code readability and error handling capabilities multifold. Cool stuff
