This package is obsoleted. Please replace it with @leismore/lmos-nodejs-lmerror
A general Error class for Node.js projects.
- Error message & error code
- HTTP response
- Error chain
npm install @leismore/lmerror
npm test
import { LMError, LMErrorErr, LMErrorRes } from '@leismore/lmerror';
let errMessage:LMErrorErr = { message: 'some error', code: 'error_001' };
let httpResponse:LMErrorRes = {
statusCode: '503',
headers: {
'Retry-After': '10',
'Content-Type': 'application/json'
},
body: {message: 'Please try again later'}
};
let previousError = new Error('previous error');
throw new LMError(errMessage, httpResponse, previousError);
public readonly error: LMErrorErr;
public readonly response?: LMErrorRes;
public previous?: Error;
public constructor(error: LMErrorErr, response?: LMErrorRes, previous?: Error)
public addPrevious(previous: Error):void
public toString(): string
Error messages:
- invalid_error_message
- invalid_error_code
- invalid_http_statusCode
- invalid_http_header
- invalid_http_body
- invalid_previous
- previous_exists
type LMErrorErr = { // Error
readonly message: string, // Message for human
readonly code: string // Code for machine
};
type LMErrorRes = { // HTTP response
readonly statusCode: string, // HTTP response status code
headers?: {readonly [key:string]: string}, // HTTP headers
body?: any // HTTP body
};
- Kyle Chine (Initial Author)
GNU Affero General Public License v3.0
Inspired greatly by http-errors