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

errorspack

v1.1.4

Published

an package for new errors, custom error and handle errors

Downloads

7

Readme

ERRORS PACK

An error pack built with pure JavaScript With help of chalk.

FEATURES

  • Built-In Errors
  • Create Custom Errors
  • Handle errors
  • Http Errors
  • Warning

INSTALLING

for starting you have to install the package by running

npm i errorspack

import the package by typing

const Error = require("errorspack")

on your file.

FUNCTIONS / BUILT-IN ERRORS

There are built in errors in this pack

SOME BUILT-IN ERRORS AND FUCTIONS ARE

  • NonStringError() - Which is for non string value for example here is a demo code:
const Errors = require("errorspack");

const Name = {
   name: Sam
}

if(typeof(Name) !== "string") {
   throw new Errors.nonStringError("Type of name must be number");
}

and the output will be:

TypeError: Type of name must be string
  • NonIntegerError() - which is for non integer value for example here ia another demo code:
 const Errors = require("errorspack");

const Age = {
    age: "26"
}

if(typeof(Age) !== "number") {
  throw new Errors.nonIntegerError("Type of age should be an Integer");
}

and the output will be:

TypeError: Type of name must be integer/number value
  • NonBooleanError() - which is for non boolean value (true/false)

HOW TO CREATE CUSTOM ERROR?

custom error can be created by a class. you have to create a class by named anything you like. After name you have to add extends. extends will be: extends CustomError

for more easier here is an example:

const { CustomError } = require('errorspack');
const Info = {
    name: 
}
class MyError extends CustomError {
    constructor(
    name = 'MyError',
    statusCode = '404',
    description = 'it\'s my error',
    isOperational: true
    ) {
        super(name, statusCode, description, isOperational)
    }

    if(typeof(Info.name === 'undifined')) {
        throw new MyError();
    }

}

VERSION 2.1

WARNING

Please note that version 0.2.0 has some changes if you have any errors with old method then please use

<packagename>.builtInErrors.<ErrorName>

ERROR HANDLING WITH ERRORSPACK

To handle a error with errorspack is very simple. First you have to create a variable with any name and the value will be a constructor.

const { Handler, uncaughtExpectationHandler, UnhandledPromiseHandler } = require('errorspack');
const Hanling = new Handler();

In handler function you have to put

'UNCAUGHT_EXPECTATION', 'UNHANDLED_REJECTION'

And the code will be:

const { Handler, uncaughtExpectationHandler, UnhandledPromiseHandler } = require('errorspack');
const Hanling = new Handler('UNCAUGHT_EXPECTATION', 'UNHANDLED_REJECTION');

Now you have to do is call the handler Here is a code:

const { Handler, uncaughtExpectationHandler, UnhandledPromiseHandler } = require('errorspack');
const Hanling = new Handler('UNCAUGHT_EXPECTATION', 'UNHANDLED_REJECTION');

unhandledPromiseHandler();
uncaughtExpectationHandler('An error caught');

NOTE: unhandledPromiseHandler() is unhandledRejection

ANTI-CRASH

Anti-Crash is same as handler but it is more easier

const { antiCrash } = require('errorspack');
antiCrash('Handled error');

easy to use :)

VERSION 1.0.0

1.0.0 is just released we have now http error

there are 3 differents http error

  • Api400ErrorBadRequest()
  • Api404ErrorNotFound()
  • Api500ErrorInternalServer()

these errors are the child of BaseError.

NOTE: BASE ERROR CAN'T BE USED BY YOU its simple to throw all the errors just:

throw new Api404ErrorNotFound();

it doesn't have any extra parameters so you can't edit the message its for every http errors.

VERSION 1.1

In version 1.1 there are warning

now you can create warning. It used console.warn() but it is more flexible and easy. using is like throwing error

throw new Warn('message here');

YOU'VE JUST LEARNED BASIC ABOUT ERRORSPACK!

STAY UPDATED