Skip to content
The general Error class for Node.js projects integrated with HTTP response.
TypeScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.gitignore
.npmignore
LICENSE
README.md
package-lock.json
package.json
tsconfig.json

README.md

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

Example

import {LMError} from '@leismore/lmerror';
// Or
const LMError    = require('@leismore/lmerror').LMError;

let errMessage   = {message: 'some error', code: 'error_001'};
let httpResponse = {
  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:       Err;
public readonly response?:   Res;
public readonly previous?:   Error;

Methods

public constructor(error: Err, response?: Res, previous?: Error)
public toString(): string

Error thrown by constructor

Error messages:

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

Types

type Err = {                // Error
  readonly message: string, // Message for human
  readonly code:    string  // Code for machine
};
type Res = {                                            // HTTP response
  readonly statusCode:  string,                         // HTTP response status code
           headers?:   {readonly [key:string]: string}, // HTTP headers
           body?:       any                             // HTTP body
};

Authors

License

MIT License

Credit

Inspired greatly by http-errors

You can’t perform that action at this time.