0
       try {
            const user = await User.create({
                username,
                password: hash,
                email,
            });
            return res.json({
                status: 'success',
                object: {
                    username: user.username,
                    email: user.email,
                },
            });
        } catch (error2) {
            return res.status(500).send('Username already in use');
        }

I'm testing to make sure you can't add the same two usernames to the database, and you can't it throws an error, but the error isnt being caught and the client never gets any type of response from the server after it makes the request. does anyone know why this is happening?

user193130
  • 8,009
  • 4
  • 36
  • 64
joe
  • 1,563
  • 4
  • 16
  • 35
  • 1
    Possible duplicate of [error handling in asynchronous node.js calls](http://stackoverflow.com/questions/5816436/error-handling-in-asynchronous-node-js-calls) – rohithpr Aug 30 '16 at 14:20
  • How are you calling this async function? –  Aug 30 '16 at 14:22
  • My guess is that there's an additional error being thrown inside your `catch` handler (does `res` exist?), which will get swallowed if you don't also handle it. – robertklep Aug 30 '16 at 16:06
  • When an exception is thrown from an `async` method, it is used to complete the promise returned from that method. It's not raised directly. – Stephen Cleary Sep 01 '16 at 02:07

0 Answers0