1.0.2 • Published 2 years ago

@operanex/ffy-errors v1.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

FFY Errors

Standard errors for FFY

Usage

Install

Install the module on your node server or service via command line ´´´ npm install @operanex/ffy-errors ´´´ Or via yarn ´´´ yarn add @operanex/ffy-errors ´´´

Generate errors

The errors are used to be handled by Express but could be used by other systems, in order to create an error perform the following

import errors from '@operanex/ffy-errors'

const err = errors.notAuthorized(`You do not have access to this API`);

Handle errors in express

import { isFFYError, errors } from '@operanex/ffy-errors'

app.use((error: FFYError|Error, req, res, next) => {
  if(isFFYError(error)) {
    res.status(error.httpCode).json({
      message : error.message,
      code: error.code,
      data: error.data 
    })
  } else {
    res.status(500).json(errors.serverError(error))
  }
})

Development

Process of publishing

1) Develop 2) Run your tests npm test or yarn test 3) Run lint npm run lint or yarn lint if there is an issue you can run npm run lint-fix or yarn lint-fix to fix them. 4) Upgrade your version by running npm version prepatch 5) Push your version