🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

error-ex

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
n

error-ex

Easy error subclassing and stack customization

1.3.2
latest
100

Supply Chain Security

100

Vulnerability

100

Quality

78

Maintenance

100

License

Version published
Weekly downloads
48M
2.55%
Maintainers
2
Weekly downloads
 
Created
Issues
2

What is error-ex?

The error-ex npm package is designed to create more customizable and informative error objects in JavaScript. It allows developers to extend the native Error type with additional properties and behaviors, making error handling and debugging more efficient.

What are error-ex's main functionalities?

Creating custom error types

This feature allows developers to create custom error types by extending the native Error object. The custom error can then be thrown with a specific message, making it easier to identify and handle specific kinds of errors in the code.

const ErrorEx = require('error-ex');
const MyError = ErrorEx('MyError');
throw new MyError('Something went wrong');

Adding properties to errors

This functionality enables the addition of custom properties to error objects. In this example, a 'code' property is added to a custom error type, which could be used to store HTTP status codes or other relevant error information.

const ErrorEx = require('error-ex');
const MyError = ErrorEx('MyError');
MyError.prototype.code = 404;
const errorInstance = new MyError('Resource not found');
console.log(errorInstance.code); // 404

Other packages similar to error-ex

FAQs

Package last updated on 19 Jun 2018

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