npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@leismore/lmos-nodejs-lmerror

v1.1.1

Published

An Error class for LMOS for Node.js project

Downloads

19

Readme

lmos-nodejs-lmerror

An Error class for LMOS for Node.js project

Features

  • Error Message & Code
  • HTTP-Response Integration
  • Chained-Errors Support
  • Timestamp

Motivation

When I wrote my first commercial Node.js project in 2019, I had been struggling to design a general error-handling module with the standard JavaScript Error object.

Because in the widely-used ECMAScript 3, the standard Error object only supports a text error message. Meanwhile in a real world server-side environment, handling an error usually means:

  1. Identifying the error by a error-message for human and a error-code for machine
  2. Recording the whole related error chain, if necessary
  3. Sending a proper HTTP response according to the error

To satisfy the requirement of Node.js environment, I have decided to introduce the LMError class to simplify and standardise the error-handling process in Node.js or other server-side JavaScript environments.

LMError class is extended from the standard Error class. By integrating with the support of error message & error code, HTTP response, and error chain, now all errors can be processed by one error-handler under a unified procedure.

Installation

npm install @leismore/lmos-nodejs-lmerror

Test

npm test

Build

npm run build

Example

import { LMError, LMErrorErr, LMErrorRes } from '@leismore/lmos-nodejs-lmerror';

let error:LMErrorErr = { message: 'an error message', code: 'error_code_1984' };

let response:LMErrorRes = {
    statusCode: '500',
    headers: {
        'Content-Type': 'text/html; charset=utf-8',
        'Content-Language': 'en-GB'
    },
    body: `<!DOCTYPE html>
           <html lang="en-GB">
             <head>
               <meta charset="UTF-8">
               <title>500 Internal Server Error</title>
             </head>
             <body>
               <h1>500 Internal Server Error</h1>
               <p>Don't cry over spilt milk</p>
             </body>
           </html>`
};

let previous = new Error('standard Error');

throw new LMError(error, response, previous);

LMError Class

Data Types

type LMErrorErr = {
  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
};

Properties

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

Methods


/**
 * 
 * @throws Error
 *   invalid_error_message
 *   invalid_error_code
 *   invalid_http_statusCode
 *   invalid_http_header
 *   invalid_http_body
 *   invalid_previous
 * 
 */
public constructor(error: LMErrorErr, response?: LMErrorRes, previous?: Error)


/**
 * 
 * @throws Error
 *   invalid_previous
 *   previous_exists
 * 
 */
public addPrevious(previous: Error):void


public toString(): string

Donation

Donate with PayPal button

License

© Leismore 2024

GNU AFFERO GENERAL PUBLIC LICENSE v3

Authors

Credits


Leismore Logo

Product of Leismore OpenSource

Leismore (Australian Business Number: 25 935 862 619) is your affordable and reliable business software provider since 2021