DEV Community

Discussion on: Why I Don't Use Async Await

Collapse
 
he_zhenghao profile image
Zhenghao He

also I am curious how you can distinguish the errors between bad url and bad internet? It seems really hard to tell them apart...
Also I am not super clear on the last section where you mentioned that "you know what type you're getting out" by type you meant the type for difference error e.g. NetworkError or TokenExpiredError so you can do exhaustive pattern matching?

Thread Thread
 
jesterxl profile image
Jesse Warden

Assuming all custom Error classes you make only extend the Error base class, then you can be confident in instanceof. If you're just doing regular JavaScript, the whole big if statements of:

if (thing instanceof OneClass) {
...
} else if (thing instanceof OtherClass) {
...
}
Enter fullscreen mode Exit fullscreen mode

That's fine; your name check works too. However, it's unsafe and you have to do by hand. Using something like TypeScript or ReScript will give you a compiler that can help you ensure you're:

  • spelling them right
  • ensuring your're checking for the correct properties
  • you've captured ALL possible errors