What's your go-to for error handling? Exceptions or returning an object?
1 / 2
Comments
- If it's only a few DB calls and low complexity, I'd go with just throwing the error.
- If it's a large and complex project, I'd use TypeScript with Effect (see screenshot).
If not: its a hacker. throw exception. Catch it later or break the app. Doesnt matter.
If its possible try:
If lsAllowedToDoStuff()
DoStuff() //see above. Throws exception.
I would read about how other languages handle that (java, c#, rust)
The exception mechanism in typescript isn't an accident but a decision that may not be loved universally.
Btw think about this:
https://stackoverflow.com/questions/63526969/how-do-you-return-multiple-values-from-a-typescript-function
Result/exception without nesting
Actually, it's not possible under normal circumstances for an unauthorized person to get the call