-
Notifications
You must be signed in to change notification settings - Fork 194
Open
Labels
featureNew functionality or improvementNew functionality or improvement
Description
Support plan
- is this issue currently blocking your project? (yes/no): no
- is this issue affecting a production system? (yes/no): no
Context
- node version: n.a.
- module version: n.a.
- environment (e.g. node, browser, native): n.a.
- used with (e.g. hapi application, another framework, standalone, ...): n.a.
- any other relevant information: n.a.
What problem are you trying to solve?
Errors now have a cause property described here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause
We should be able to easily set the cause when creating a Boom error.
Currently, the following must be done:
try {
// Stuff
} catch (err) {
throw Object.assign(badImplementation('Stuff should not throw an error'), { cause: err })
}Do you have a new or modified API suggestion to solve the problem?
It is my understanding that currently, in the Hapi ecosystem, the data property of Boom errors is sometimes used to contain the original error, so anything proposed here will likely largely impact the Hapi ecosystem.
in order not to break the current api too much, we could just add a new option on error creators:
export function badImplementation<Data>(message?: string, data?: Data, errorOptions?: { cause?: unknown }): Boom<Data>;and specify that from now on, data should no longer be used to contain the originating error.
function sqlQuery(query, values) {
try {
// Execute some SQL
} catch (err) {
throw internal('Failed to query DB', { code: "sql-query-error", query, values }, { cause: err })
}
}Metadata
Metadata
Assignees
Labels
featureNew functionality or improvementNew functionality or improvement