title: Handling operational erros in node.js
body: <p>Let's say, hypothetically, we've got an array of objects that contains users and their IDs, like the following:</p>
  
  <pre><code>var Users = [{
    id: 1,
    name: "Bob",
  },
  {
    id: 2,
    name: "Alice",
  },
  {
    id: 3,
    name: "Pete",
  }];
  </code></pre>
  
  <p>Now, if I had an asynchronous function that tried to get a user by their ID <strong>using user input</strong> (meaning that this function will be receiving their id from an untrusted source), it could look like the following:</p>
  
  <pre><code>function getUser(id) {
    var user = Users.filter(user =&gt; user.id === id);
    // working with input
    user.age = 12;
  }
  </code></pre>
  
  <p>Now, of course this all is just an example.
  However, if - in the above function - a non-valid or nonexistent id would be provided by the user and worked with (e.g. <code>user.age = 12</code>), an error would be thrown. </p>
  
  <p>Since this error is not a programmatical error, nodejs shouldn't crash - but obviously, it still will. And with one function, this isn't a huge problem (a small <code>if</code> check wouldnt hurt) - but wrapping tens of hundreds of functions in try/catch blocks isn't optimal.</p>
  
  <p>How can I handle operational errors en masse?</p>
  
  <p>And last but not least, how would one go about this if the function was working with data asynchronously?</p>