hapijs / boom

HTTP-friendly error objects
Other
2.94k stars 192 forks source link

feat: allow boomifying any value (#291) #293

Closed matthieusieben closed 2 years ago

matthieusieben commented 2 years ago

Creation of a new boomifyAny that allows creating a boom error from an unknown value.

This is a proposed fix for https://github.com/hapijs/boom/issues/291

matthieusieben commented 2 years ago

Please tell me if you are ready to accept before I implement the tests.

For context, here is how this would be used:

try {
  // some code that throw using non-error
} catch (err) {
  // in TypeScript err is of type unknown
  throw boomifyAny(err, { message: 'Unexpected error while performing code that throws non-error' })
}
kanongil commented 2 years ago

Personally, I would much prefer to do a breaking change to boomify, as suggested in https://github.com/hapijs/boom/issues/291#issuecomment-997863811, which would also update the argument type to any.

matthieusieben commented 2 years ago

Edit moved comment to https://github.com/hapijs/boom/issues/291#issuecomment-1119474178