Search code examples
node.jsazureexpressiisnode

ExpressJS: The custom error module does not recognize this error


I'm running an Express.JS backend, and have it set to return a 422 error with a custom message if a user attempts to sign up with an email that's already in use, like so:

const existingUser = await User.findOne({ email: email });
    if (existingUser) {
        return res.status(422).send({ error: 'Email is already in use' });
    }

However, the response I see on the front end is this:

"response":{"data":"The custom error module does not recognize this error.","status":422,"statusText":"Unprocessable Entity"

Something is, apparently, changing the error on the way to the front end.

I'm running this locally right now for development, but the production is deployed to Azure, so I have a Web.config file and an iisnode.yml one. I've added this code to the former, to make sure it's not causing the problem:

<system.webServer>
  <httpErrors existingResponse="PassThrough">
  </httpErrors>
</system.webServer>

How do I go about troubleshooting this thing?


Solution

  • Not sure, but following should work.

    return res.status(422).send('Email is already in use');