Have catch block return statement exit from parent function as well

Hello, I’m working with async, await and promises from within nodejs/express and I have this issue: In the catch block after my await, I want the return to also cause the parent function (in this case it’s a GET handler function) to return as well. However it doesn’t during a rejected promise from await, and code still executes as such:

app.route('/theRoute').get(function (req, res) {

  let result = await getPromiseThatRejects(data)
    .catch((error) => {
      res.send(error);
      return;
    })

 //additional code that I don't want executed if promise got error
  console.log("In the case of an error, this code still executes when I don't want it to")
})

This is the only solution I found:

app.route('/theRoute').get(function (req, res) {

  let success = true
  let result = await getPromiseThatRejects(data)
    .catch((error) => {
      success = false
      res.send(error); 
    })

  if (!success) return
  console.log("Code no longer executes if there was an error, which is my goal")
})

So basically I just have to check the boolean after the await is done and return if it’s false. But is there a more eloquent way to do this without having to use extra lines for boolean checks, or am I stuck with this technique for now.

This isn’t correct syntax for async await, the handler has to use the async keyword. And you’re mixing the two syntaxes, which isn’t an issue, it’s just a bit confusing

app.route('/theRoute').get(async (req, res) => {
  try {
    let result = await getPromiseThatRejects();
    res.doSomething(result) // ??
  } catch (error) {
    return next(error); // ?? Something like that, pass on to error handler
  }
});

Apologies, my app has async in the get function but I forgot to include it in this example. Yes, that way works. Heh, I was doing it my way because I didn’t like all the extra brackets from putting in the try block, but that works better. Thanks.