title: Properly handling errors with Node/Express
body: <p>Which is the proper way to return errors with your server in general (node/express) and reject a promise?</p>
  
  <hr>
  
  <p><strong>A)</strong> Like this: <code>res.json({status: 1, message: 'Test missing phone.', error: 'phone'})</code></p>
  
  <p>And then pull the error 'code' out of <code>error</code> and the message out of <code>messsage</code> on your front end, resulting in a fulfilled promise that has an <code>error</code> and <code>message</code> in it.</p>
  
  <hr>
  
  <p><strong>B)</strong> Like this;</p>
  
  <pre><code>res.status(500)
  res.json({message: 'Test missing phone.'})
  </code></pre>
  
  <p>And then just pull <code>message</code> out and call <code>.reject</code> with the message. Or <code>res.error</code> or something.</p>
  
  <hr>
  
  <p>Do either of these cause a 'rejected' promise or 'error' callback that would make frontend stuff easier? </p>
  
  <p>Should I be causing promise/callback rejection when I get an error, or just send a fulfilled promise with an error in the object like <strong>A</strong>?</p>
  
  <p>Which of these is the 'correct' way to return an error from your server to your front end?</p>
  
  <p>Currently I use method A, but it seems pretty dumb because I have to handle the error twice, backend (to actually send the custom error) and frontend (to check if the fulfilled promise has an error object, and then display a popup). Method B would eliminate the 'checking if the fulfilled promise has an error object' part, since a rejected promise is an error by nature.</p>
  
  <p>EDIT: I'm using React Native as frontend.</p>
  
  <p>EDIT2: If you <code>res.status(500).json({test: 'Test missing phone.'})</code> on your backend you can <code>console.log(error.response.data)</code> on the frontend to make "B" a viable option.</p>