Video není dostupné.
Omlouváme se.
Better Application architecture with Error Handling | Expressjs
Vložit
- čas přidán 30. 01. 2022
- Error handling is something that is super important when it comes to huge production applications. For this video I will be using Expressjs with TypeScript, however do note that the theory is something that can be applied regardless of what language or framework you use.
I got this in writing: frostzt.vercel.app/blog/error...
Express Error Handling: expressjs.com/en/guide/error-...
Express Async Errors: www.npmjs.com/package/express...
This was really great. Ive been working on handling errors for a little over 2 weeks and this has really solidified things. Now to figure out database errors......
Much better than the previous two error handling videos I watched! I have two questions:
1. How can we throw and send multiple errors, like in a registration form if the user forgot to enter both an email and a password?
2. Why does the object lose its prototype and we have to set its prototype to the prototype of itself?
Hey thanks! So to answer your questions,
1. If you wanna do that I would say you can push to the errors array that we return in that way you're capable of returning more than one errors!
2. This one I myself don't know why I did, so for clarification I don't think this should be needed! And here is the reason, `Object.setPrototypeOf` is used to assign prototypes to the object, however this is useful to setup inheritance when we use the `function` way of creating classes which is what JS have! So essentially it is useful to setup the prototypical inheritance chain! I think you can skip it (if using modern JS)!
For multiple errors you can probably create an AggregateError class which takes an array of Errors and serializes them (you may need a helper function to aggregate specific Error classes), or maybe something specific like a ValidationError just for handling form validation errors. You can get creative here, but I suggest an AggregateError class would do just fine so as to avoid creating unnecessary error classes.
thank you so much for the great tutorial man! you mad my day : )
Excellent video 👍
Thank you very helpful!
thank you so much for the tutorial , helped me a lot, one question , what's the name of your vscode theme ?
If you see on top right the status code is always 200. How’d you go about to fix that?
28:02 the "err instanceof CustomError" will always be true, so what's the point of checking
That’s not the case ‘err instanceof CustomError’ will only be true when you throw an error that was an instance of CustomError means the CustomError and all of its Children classes, however the libraries that you use or anything else that is not your code will throw just an Error NOT CustomError that’s why the check!
@@itsfzt ok now I understand, I just got confused there.
Just one more question: why not "err instanceof ValidationError"? cause it will make more sense as all the instances that you created are using "ValidationError"
you said delopment instead of development. a friend of mine also always says delopment hahah
Weird I generally slip up sometimes.
besides that very good and fluent english!
Bro, class is really good but your copied indian english accent is hilarious. Please be original