Back

There isnt res.status - how do I forward an error to the client?

  • 0
  • Self Hosted
  • Functions
_alnes_
22 Aug, 2024, 10:30

Its an easy question. Ive this try/catch:

TypeScript
  try {
    const userResponse: Models.User<Models.Preferences> = await users.get(id);
    const user = JSON.stringify(userResponse);

    return res.send(user);
  } catch (err) {
    log('Appwrite getUser: Error getting user. id: ' + id);
    return res.send(err);
  }```

Since there is no res.status, what is the best way to send an error to the client? Just res.send it? This will not trigger the try/catch error handling on the client...

thanks πŸ™‚
TL;DR
To forward an error to the client without res.status in an Express application, developers can set the statusCode manually to a 4xx code. A common approach is to use the res.send method to send the error message to the client but keep in mind that this may not trigger the try/catch error handling on the client side.
Joshi
22 Aug, 2024, 10:43

set statusCode to 4xx

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more