Socket
Socket
Sign inDemoInstall

err-code

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

err-code

Create an error with a code


Version published
Maintainers
1
Created

What is err-code?

The 'err-code' npm package is a utility for creating error objects with custom error codes and properties. It simplifies the process of adding additional context to errors, making them more informative and easier to handle.

What are err-code's main functionalities?

Creating an error with a custom code

This feature allows you to create an error object with a custom error code. The custom code can be used to identify the error type more easily.

const createError = require('err-code');
const error = createError(new Error('Something went wrong'), 'E_CUSTOM');
console.log(error.code); // 'E_CUSTOM'

Adding custom properties to an error

This feature allows you to add custom properties to the error object, providing additional context and information about the error.

const createError = require('err-code');
const error = createError(new Error('Something went wrong'), 'E_CUSTOM', { detail: 'Additional error details' });
console.log(error.detail); // 'Additional error details'

Handling errors with custom codes

This feature demonstrates how to handle errors based on their custom codes, allowing for more specific error handling logic.

const createError = require('err-code');
try {
  throw createError(new Error('Something went wrong'), 'E_CUSTOM');
} catch (error) {
  if (error.code === 'E_CUSTOM') {
    console.error('Custom error occurred:', error.message);
  }
}

Other packages similar to err-code

Keywords

FAQs

Package last updated on 14 Jan 2016

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