nhost / hasura-backend-plus

🔑Auth and 📦Storage for Hasura. The quickest way to get Auth and Storage working for your next app based on Hasura.
https://nhost.github.io/hasura-backend-plus/
MIT License
1.17k stars 187 forks source link

Use express-boom-v2 #471

Closed komninoschatzipapas closed 3 years ago

komninoschatzipapas commented 3 years ago

We currently use the @hapi/boom package directly for our HTTP errors. I propose we instead use this package which wraps @hapi/boom as an express middleware.

Doing so will result in more testable and clearer code:

throw Boom.badImplementation('SMTP settings unavailable') // Uses throw and weird global variable, bad practice.

vs.

return res.boom.badImplementation('SMTP settings unavailable') // 🚀
komninoschatzipapas commented 3 years ago

Furthermore, Boom errors are sometimes used outside of routes, e.g. on jwt.ts:

if (!jwtKey) {
  throw Boom.badImplementation('Empty JWT secret key.')
}

We should just throw regular Errors in cases like the above.

elitan commented 3 years ago

I like your suggestion and the syntax of returning the http error instead 👍 . Maybe @plmercereau wants to weigh in?