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 🙏

© 2026 – Pkg Stats / Ryan Hefner

errorme

v1.3.3

Published

Error manager for handling errors within the classes by creating self defined error codes and parsing them into http error codes

Readme

NSP Status Build Status

Overview

This node module helps you to create your own errors with your defined error codes and handle them within classes in a proper way.

Features

  • Creating errors objects instance of Error class from the self-defined error codes
  • Throw the created error any time with informative error message/code and error stack
  • Parse any error to HTTP error codes and messages
  • Usage with express middleware
  • See custom and informative error messages in the client-side of the REST in development environment

ECMAScript support

ES6 only

Installation

$ npm install errorme

API

Check the JSDoc here.

#Installation npm install errorme --save

#Usage You can add your custom errors or use the default errors.

//defining our custom errors
const errors = {
	"ValidationError": {
		"CODE": 100,
		"DEFAULT_MESSAGE": "The provided data is not valid",
		"HTTP_CODE": 400
	},
	"ServiceError": {
		"CODE": 101,
		"DEFAULT_MESSAGE": "Error happend related to the third party service",
		"HTTP_CODE": 500
	},
}
//overwriting defaults errors and requiring to show logs once an error created
let options = { overwrite: true, showLogs: true }
//requiring module
let errorme = require('errorme')(errors, options)

//getting error
let code = 100, customMessage = "The provided data is invalid"; 
let err = errorme.getError(code, customMessage) //custom message will be visible if process.env.DEV=true
console.log(err instanceof Error) //true
//parsing error to http
let httpErr = err.parseTo('http')
console.log(httpErr.code) //400
console.log(httpErr.definedCode) //100
console.log(httpErr.message) //"Bad request"

//create http error
let newHttpErr = errorme.getHttpError(100);
console.log(newHttpErr.code == httpErr.code) //true
console.log(newHttpErr.message == httpErr.message) //true

Examples

To understand the real use case it will be better to see it with async module, especially with async/waterfall

let waterfall = require('async/waterfall');
let errorme = require('errorme')();

let someFunction = (params, callback)=>{
	waterfall([
		(_calllback)=>{
			//suppose here we are doing some database query
			//and it might fail
			let err;
			let data;
			if(Math.floor((Math.random() * 5)) == 0){
				//suppose here we've got  error
				err = errorme.getError(102, "Our database query unfortunately failed")
			}else{
				data = "Some data retrieved from database"
			} 
			_calllback(err, data) //err will be undefined if the if block is not executed
		},
		(data, _calllback)=>{
			//if this callback is being executed then it means the previous is not failed
			//and now we want to check our data which might not to meet to our criteria 
			let err;
			if(Math.floor((Math.random() * 5)) == 1){
				//data doesn't meet to our criteria
				//and we want to provide the corresponding error
				err = errorme.getError(100, "Data doesn't meet to our criteria")
				data = null;
			} 
			_calllback(err, data) //err will be undefined if the if block is not executed
		},
		(data, _calllback)=>{
			//soppose here we want to make a call to some external service which also can be failed
			let err;
			let dataOfExternalService;
			if(Math.floor((Math.random() * 5)) == 2){
				err = errorme.getError(101); //if don't pass message then the error message will be the default error message
			}else{
				dataOfExternalService = "Data from external service";
			} 
			_calllback(err, dataOfExternalService) //err will be undefined if the if block is not executed
		},
	], (error, data)=>{
		//here we can do our final operations 
		//and finally parse the error to http and send to the client
		// if(error)
		// 	error = error.parseTo('http');
		
		//we don't have anything to do in this final block then we could parse the error into http
		//in the above callbacks and as a callback we could just give the top most callback
		//lets say we don't want to parse to http. We just pass the pure error to the callback
		callback(error, data);		
	})
	
}

someFunction("some paramas", (error, data)=>{
	if(error){
		console.log('Error occured. Code: ' + error.code + ', message: ' + error.message);
	}
	if(data){
		console.log('Data: ' + data);
	}
});

Using with express

let express = require('express');
let app = express();
let errorme = require('errorme')();

//creates middleware
errorme.middleware(app);
 
app.get('/', function (req, res) {
	let data = {
		foo: "Foo data"
	}
	let err;
	
	// uncoment below if you want to send http error message (data argument will be ignored)
	// err = errorme.getError(100);
	res.errormeSend(err, data);
});
 
app.listen(3000);

Next features

  • Will be ability to add other "error languages"
  • Optimization for working with error codes defined by external service providers

License

MIT