@operanex/ffy-errors
v1.0.2
Published
Standard errors for FFY
Downloads
6
Readme
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
- Develop
- Run your tests
npm test
oryarn test
- Run lint
npm run lint
oryarn lint
if there is an issue you can runnpm run lint-fix
oryarn lint-fix
to fix them. - Upgrade your version by running
npm version prepatch
- Push your version