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

error-key

v1.0.2

Published

simplify your project error handling & conveying issues to outside world

Downloads

41

Readme

ts Test codecov npm npsr install size Buy us a tree Conventional Commits License: Unlicense

About

This is a completely free public domain software, read more in the end

  • error-key is use to simplify your project errors & give them unique numbers for easy identification. Quite helpful in case of rest apis where you wish to convey what caused the error & also able to track down the error/bug internally.
  • for APIs specifically you can also easily fetch statusCode to return from your error code ; no more guessing / writing deep logic for exact statusCode to send

Quick Code

  • define an object with the following format (learn about the format below)
const errorObj = {
	404 : {
		"userNotFound": "userNotFound",
		"orgNotFound": "orgNotFound"
	},
	500 : {
		"unknown: "unknown"
	}
}
  • next initialize in start of your project
const errorKey = require("error-key");

errorKey.initErrors([], errorObj) // initializing
errorKey.keys() // will return object of unique keys with unique codes
errorKey.map() // return object similar to config file with unique code mapping
// you can simply get unique error code anywhere
try{
	// ....
}catch(err){
	const uniqueCode = errorKey.keys().invalidKey;
	// uniqueCode is a number eg: 4001011 or 5021012
	// read more detail about them below
}

Working

You start by creating a unique configuration object anywhere in your project which you can pass to the initErrors object.

  • The config file is quite simple to understand. The first nesting is your statusCode keys & in each key the error that you wish to declare with both key & value name similar.
  • All common status codes (for errors) are covered between 400 - 600 although if you wish to use some other error code you have to pass it inside initErrors function (see below)
  • You can only provide status codes you need and skip the others

Note: The above example (in quick code) is the way your config object should be structured. You will receive an error while initializing if incorrect format is provided.

Initialization

Simply initialize this anywhere in your project (ofcourse recommended way is in the very start itself)

  • initErrors(codes, config)
    • codes : array of numbers - if you wish to provide custom statusCodes (provide [] if no custom codes)
      • example: init([888,999], errorObj)
    • config: your configuration object (learn about config object above)
      • example: init([], errorObj)

Contact

Twitter - @dawnimpulse
Email - [email protected]

Treeware

This package is Treeware. If you use it in production, then we ask that you buy the world a tree to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

The Unlicense

error-key is free and unencumbered public domain software. 

For more information, see http://unlicense.org/ or the accompanying UNLICENSE file. 

Written with StackEdit.