Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

meseeks

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

meseeks

Tiny and plugeable error handler with zero dependencies.

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Tiny Error handler

Tiny and plugeable error handler with zero dependencies.

Quick usage

const { ApplicationError } = require('meseeks');

class DatabaseError extends ApplicationError {
    constructor(message, status, code) {
        super(message, status, code);
    }
}

const dbError = new DatabaseError('Critical error.', 500, 3500);

// Console output
// { date: 'Mon, 04 May 2020 17:04:50 GMT',
//  http_status: 500,
//  message: 'Critical error.',
//  code: 3500,
//  stack:
//   'Error\n at DatabaseError.ApplicationError ...' }

Base class

The package contains a base class named ApplicationError with the follow properties and methods:

PropertyTypeDescription
_messageprivateCustom error message.
_codeprivateApplication specific error code.
_statusprivateHTTP status code.
_debugprivateDebug flag. Default true
_errorprivateError in JSON format with properties: name, message, status and code.
getError()publicReturns the _error object.

API

The base class contains a couple of static methods to make it plugeable.

$config

This static method allows change, for now, the debug flag.

 ApplicationError.$config({ debug: false });

$addEvent

The base class contains an events stack that executes when a instance occur. You can add custom events for all the subclasses or for a specific subclass, and the method can access to the private properties and methods shown in the previous table.

For all subclasses:

const { ApplicationError } = require('meseeks');

function customLog() {
    console.log(`My HTTP status is: ${this._status}`);
}

ApplicationError.$addEvent(customLog);

class DatabaseError extends ApplicationError {
    constructor(message, status, code) {
        super(message, status, code);
    }
}

const dbError = new DatabaseError('Critical error.', 500, 3500);

// Console output
// { date: 'Mon, 04 May 2020 17:04:50 GMT',
//  http_status: 200,
//  message: 'Critical error.',
//  code: 500,
//  stack:
//   'Error\n at DatabaseError.ApplicationError ...' }
// My HTTP status is 500

For a specific subclass:

const { ApplicationError } = require('meseeks');

function customLog() {
    console.log(`My HTTP status is: ${this._status}`);
}

class DatabaseError extends ApplicationError {
    constructor(message, status, code) {
        super(message, status, code);
    }
}

class DatabaseError2 extends ApplicationError {
    constructor(message, status, code) {
        super(message, status, code);
    }
}

DatabaseError.$addEvent(customLog);

const dbError = new DatabaseError('Critical error.', 500, 3500);
const dbError2 = new DatabaseError('Critical error 2.', 509, 3100);

// Console output
// { date: 'Mon, 04 May 2020 17:04:50 GMT',
//  http_status: 500,
//  message: 'Critical error.',
//  code: 3500,
//  stack:
//   'Error\n at DatabaseError.ApplicationError ...' }
// My HTTP status is 500
// { date: 'Mon, 04 May 2020 17:04:50 GMT',
//  http_status: 509,
//  message: 'Critical error.',
//  code: 3100,
//  stack:
//   'Error\n at DatabaseError2.ApplicationError ...' }

Keywords

FAQs

Package last updated on 04 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc