title: Validate URLs in nodejs + express to handle bad request errors
body: <p>Well, after reading some things about this issue, i decide to ask about.</p>
  
  <p>The idea is simple in the core: detect incoming invalid URL's/URI's and return a response to the client with the pertinent code/data.</p>
  
  <p>Normally, when treat the errors in node, we use syntax like:</p>
  
  <pre><code>if (err) {
      return res.status(500).json(error: {msg: err.message, stack: err.stack});
  }
  </code></pre>
  
  <p>Okay, that is pretty simple but the essential thing is that we detect: <strong>"hey, if an error occurs, shoot this thing to the client"</strong>.</p>
  
  <p>But what if it's not an 500 internal? As i know, bad request errors are send like a client error and have their own stack, type and message in the prompt, rigth?</p>
  
  <p>Reading <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error" rel="nofollow">This</a>, i found the URIError constructor, that points to an instance representing an error that occurs with ivalids URI's. So, it's possible to make some like this:</p>
  
  <pre><code>if (err instanceof URIError) { /* send a handler for bad request */ };
  </code></pre>
  
  <p>Or i need to validate from scratch the URI and make my own error inheritance?</p>
  
  <p>Any hint? Idea? ... Thanks in advance! &lt;3</p>