luin / express-promise

❤️ Middleware for easy rendering of async Query results.
MIT License
316 stars 19 forks source link

Standardize error returns #12

Open wmertens opened 9 years ago

wmertens commented 9 years ago

Would be nice if express-promise provided an HttpError object that can be thrown from promises to result in a certain HTTP error.

ieugen commented 9 years ago

+1.

I haven't seen any code regarding error handling. What happens when the promise fails?

karl-gustav commented 9 years ago

+1

I also wonders what happens when promises fail?

Daerdemandt commented 5 years ago

what happens when promises fail?

next is used as a callback, so the first promise to reject gets its error there. This error gets handled by express as usual (sending error message to user with a 500 status).

This is sometimes a security problem, but it's a general express feature, not unique to this package.

However, if you just do Promise.reject() somewhere then err will be undefined. This would make other middleware think everything is fine and empty response with code 200 would be sent to the user.

As for OP, now you can use https://github.com/jshttp/http-errors