code: function onProxyError(proxy) {
    return (err, req, res) => {
      const host = req.headers && req.headers.host;
      console.log(
        chalk.red('Proxy error:') +
          ' Could not proxy request ' +
          chalk.cyan(req.url) +
          ' from ' +
          chalk.cyan(host) +
          ' to ' +
          chalk.cyan(proxy) +
          '.'
      );
      console.log(
        'See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (' +
          chalk.cyan(err.code) +
          ').'
      );
      console.log();
  
      // And immediately send the proper error response to the client.
      // Otherwise, the request will eventually timeout with ERR_EMPTY_RESPONSE on the client side.
      if (res.writeHead && !res.headersSent) {
        res.writeHead(500);
      }
      res.end(
        'Proxy error: Could not proxy request ' +
          req.url +
          ' from ' +
          host +
          ' to ' +
          proxy +
          ' (' +
          err.code +
          ').'
      );
    };
  }
docs: We need to provide a custom onError function for httpProxyMiddleware. It allows us to log custom error messages on the console.