📦 Errors Spool
A Spool to extend Fabrix with Standard Errors
$ npm install --save @fabrix/spool-errors
// config/main.ts
import { ErrorsSpool } from '@fabrix/spool-errors'
export const main = {
spools: [
// ... other spools
ErrorsSpool
]
}
You can easily extend the generic errors
// config/errors.ts
import { GenericError } from '@fabrix/spool-error/errors'
export const errors = {
TestError: class TestError extends GenericError {}
}
Use spool-errors to standardize Joi errors
const schema = Joi.object({
username: Joi.string()
.alphanum()
.min(3)
.max(30)
.required(),
})
const test = schema.validate({})
const { value, error } = this.app.transformJoiError(test, TestError)
if (error) {
assert(error instanceof TestError)
throw error
}
else {
// do something with value
}