@beecode/msh-error
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

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

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

Readme

Keywords

none

Package Sidebar

Install

npm i @beecode/msh-error

Weekly Downloads

39

Version

1.0.3

License

mit

Unpacked Size

118 kB

Total Files

47

Last publish

Collaborators

  • milosbugarinovic