1.6.2 • Published 5 years ago

@fabrix/spool-errors v1.6.2

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

spool-errors

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

:package: 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
}
1.6.2

5 years ago

1.6.1

5 years ago

1.6.0

5 years ago