title: Catching error client side with JSON payload using Next.js and custom server
body: <p>I'm using Next.js with a custom server (Express) and coming across an issue with basic api error handling.</p>
  
  <p>I have some simple error handling middleware which looks similar to this:</p>
  
  <pre><code>app.use((err, req, res) =&gt; {
      res.status(400).send(message);
  });
  </code></pre>
  
  <p>If <code>message</code> is a string I'm able to catch the error client-side (when using fetch and promises). However if I use something like:</p>
  
  <pre><code>res.status(400).send({ message });
  </code></pre>
  
  <p>This does not get caught but I can access the payload within the <code>then</code> handler of the promise. How can I send an error response with a json payload that can be caught in the <code>catch</code> handler? </p>