Skip to content

fabrix-app/spool-errors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

14ec2b2 Β· Oct 21, 2019

History

6 Commits
Oct 17, 2019
Oct 17, 2019
Oct 17, 2019
Oct 17, 2019
Oct 21, 2019
Oct 21, 2019
Oct 17, 2019
Oct 17, 2019
Oct 21, 2019
Oct 17, 2019
Oct 17, 2019
Oct 21, 2019
Oct 21, 2019
Oct 17, 2019

Repository files navigation

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
}