This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

@leismore/lmerror
TypeScript icon, indicating that this package has built-in type declarations

6.0.3 • Public • Published

LMError

A general Error class for Node.js projects.

  • Error message & error code
  • HTTP response
  • Error chain

Donation

Buy me a coffee via PayPal Donation

Installation

npm install @leismore/lmerror

Test

npm test

Example

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);

Class Structure

Properties

public readonly error:       LMErrorErr;
public readonly response?:   LMErrorRes;
public          previous?:   Error;

Methods

public constructor(error: LMErrorErr, response?: LMErrorRes, previous?: Error)
public addPrevious(previous: Error):void
public toString(): string

Error thrown by constructor and addPrevious

Error messages:

  • invalid_error_message
  • invalid_error_code
  • invalid_http_statusCode
  • invalid_http_header
  • invalid_http_body
  • invalid_previous
  • previous_exists

Types

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
};

Authors

License

GNU Affero General Public License v3.0

Credit

Inspired greatly by http-errors

Package Sidebar

Install

npm i @leismore/lmerror

Weekly Downloads

0

Version

6.0.3

License

AGPL-3.0-only

Unpacked Size

44.8 kB

Total Files

15

Last publish

Collaborators

  • kyle.chine.leismore