@beecode/msh-error
v1.0.6
Published
[![Build Status](https://beecode.semaphoreci.com/badges/msh-error/branches/main.svg?style=shields)](https://beecode.semaphoreci.com/projects/msh-error) [![codecov](https://codecov.io/gh/beecode-rs/msh-error/branch/main/graph/badge.svg?token=fHc0YaxEiB)](h
Downloads
24
Readme
msh-error
Micro-service helper: node error
This project is intended to be used in typescript project.
Install
npm i @beecode/msh-error
Documentation
Usage
import { errorFactory } from '@beecode/msh-error'
export const testService = {
someFunction: () => {
// ...
if(isThereAnError) {
throw errorFactory().client.forbidden();
// FORBIDDEN: 403 - FORBIDDEN
// at Object.closure ...
// at file:...
// at ModuleJob.run (node:...) {
// httpCode: 403,
// payload: undefined
// }
}
// ...
}
}
With custom message
import { errorFactory } from '@beecode/msh-error/dist/error/factory';
export const testService = {
someFunction: () => {
// ...
if(isThereAnError) {
throw errorFactory().client.forbidden('Some custom message');
// FORBIDDEN: Some custom message
// at Object.closure ...
// at file:...
// at ModuleJob.run (node:...) {
// httpCode: 403,
// payload: undefined
// }
}
// ...
}
}
Pass some payload
import { errorFactory } from '@beecode/msh-error/dist/error/factory';
export const testService = {
someFunction: () => {
// ...
if(isThereAnError) {
throw errorFactory().client.forbidden({ message:"Some custom message", payload: { some:"custom", data:"here" } });
// FORBIDDEN: Some custom message
// at Object.closure ...
// at file:...
// at ModuleJob.run (node:...) {
// httpCode: 403,
// payload: { some: 'custom', data: 'here' }
// }
}
// ...
}
}