How do you js/typescript wizards catch multiple types of exceptions since there are (still) no type annotations on catch clauses? #js #typescript
@jorisvaesen Something like: isNativeError(error) ? error.message : typeof error === ‘string’ ? error: ‘unknown’ and you put that in a function like describeError or whatever you like or a function that logs it the way you like. Depending on how you handle exceptions.

@airtwee
But what if you would take different actions based on the exception type?

Like handling an ApiException differently than a TypeError, for example.

I'm really curious if all devs create their own handling system which seems so off to me for something standard as exception handling.

@jorisvaesen then I write an typecheck function isApiError(error: unknown): error is ApiError. However I do not use this often, but it can come in handy. To differentiate between more as two error types never happend to me yet, so a simple if is mostly sufficient