title: How to use instanceof in a switch statement
body: <p>I use custom errors (<a href="https://www.npmjs.com/package/es6-error" rel="noreferrer">es6-error</a>) allowing me to handle errors based on their class like so:</p>
  
  <pre><code>import { DatabaseEntryNotFoundError, NotAllowedError } from 'customError';
  
  function fooRoute(req, res) {
    doSomethingAsync()
      .then(() =&gt; {
        // on resolve / success
        return res.send(200);
      })
      .catch((error) =&gt; {
        // on reject / failure
        if (error instanceof DatabaseEntryNotFoundError) {
          return res.send(404);
        } else if (error instanceof NotAllowedError) {
          return res.send(400);
        }
        log('Failed to do something async with an unspecified error: ', error);
        return res.send(500);
      };
  }
  </code></pre>
  
  <p>Now I'd rather use a switch for this type of flow, resulting in something like:</p>
  
  <pre><code>import { DatabaseEntryNotFoundError, NotAllowedError } from 'customError';
  
  function fooRoute(req, res) {
    doSomethingAsync()
      .then(() =&gt; {
        // on resolve / success
        return res.send(200);
      })
      .catch((error) =&gt; {
        // on reject / failure
        switch (error instanceof) {
          case NotAllowedError:
            return res.send(400);
          case DatabaseEntryNotFoundError:
            return res.send(404);
          default:
            log('Failed to do something async with an unspecified error: ', error);
            return res.send(500);
        }
      });
  }
  </code></pre>
  
  <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof" rel="noreferrer">instanceof</a> doesn't work like that however. So the latter fails.</p>
  
  <p>Is there any way to check an instance for its class in a switch statement?</p>