1.0.6 • Published 2 days ago

@beecode/msh-error v1.0.6

Weekly downloads
-
License
mit
Repository
github
Last release
2 days ago

Build Status codecov GitHub license
NPM

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' }
			// }
		}
		// ...
	}
}
1.0.6

2 days ago

1.0.5

5 days ago

1.0.4

6 days ago

1.0.3

24 days ago

1.0.2

30 days ago

1.0.1

1 month ago

1.0.0

1 month ago

0.1.1

12 months ago

0.1.0-alpha

1 year ago