@fabrix/spool-errors
TypeScript icon, indicating that this package has built-in type declarations

1.6.2 • Public • Published

spool-errors

Gitter NPM version Build Status Test Coverage Dependency Status Follow @FabrixApp on Twitter

📦 Errors Spool

A Spool to extend Fabrix with Standard Errors

Install

$ npm install --save @fabrix/spool-errors

Configure

// config/main.ts
import { ErrorsSpool } from '@fabrix/spool-errors'
export const main = {
  spools: [
    // ... other spools
    ErrorsSpool
  ]
}

Configuration

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 {}
}

Usage

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
}

Package Sidebar

Install

npm i @fabrix/spool-errors

Homepage

fabrix.app

Weekly Downloads

1

Version

1.6.2

License

MIT

Unpacked Size

29.8 kB

Total Files

40

Last publish

Collaborators

  • scottbwyatt