Which is the proper way to return errors with your server in general (node/express) and reject a promise?
A) Like this: res.json({status: 1, message: 'Test missing phone.', error: 'phone'})
And then pull the error 'code' out of error and the message out of messsage on your front end, resulting in a fulfilled promise that has an error and message in it.
B) Like this;
res.status(500)
res.json({message: 'Test missing phone.'})
And then just pull message out and call .reject with the message. Or res.error or something.
Do either of these cause a 'rejected' promise or 'error' callback that would make frontend stuff easier?
Should I be causing promise/callback rejection when I get an error, or just send a fulfilled promise with an error in the object like A?
Which of these is the 'correct' way to return an error from your server to your front end?
Currently I use method A, but it seems pretty dumb because I have to handle the error twice, backend (to actually send the custom error) and frontend (to check if the fulfilled promise has an error object, and then display a popup). Method B would eliminate the 'checking if the fulfilled promise has an error object' part, since a rejected promise is an error by nature.
EDIT: I'm using React Native as frontend.
EDIT2: If you res.status(500).json({test: 'Test missing phone.'}) on your backend you can console.log(error.response.data) on the frontend to make "B" a viable option.
500only for errors that should not happen (database unavailable, log file full).