Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
extendable-error
Advanced tools
The extendable-error npm package provides a simple way to create custom error classes in JavaScript by extending the built-in Error class. This is useful for creating more specific error types in your applications, which can help with error handling and debugging.
Creating a Custom Error Class
This feature allows you to create a custom error class by extending the ExtendableError class. The custom error class can have its own name and additional properties or methods if needed.
class MyCustomError extends ExtendableError {
constructor(message) {
super(message);
this.name = 'MyCustomError';
}
}
try {
throw new MyCustomError('Something went wrong!');
} catch (error) {
console.error(error.name); // MyCustomError
console.error(error.message); // Something went wrong!
console.error(error.stack); // Stack trace
}
Handling Custom Errors
This feature demonstrates how to handle custom errors by checking the instance of the error. This allows for more specific error handling logic based on the type of error.
class DatabaseError extends ExtendableError {
constructor(message) {
super(message);
this.name = 'DatabaseError';
}
}
try {
throw new DatabaseError('Database connection failed!');
} catch (error) {
if (error instanceof DatabaseError) {
console.error('A database error occurred:', error.message);
} else {
console.error('An unknown error occurred:', error.message);
}
}
The custom-error-generator package provides a way to create custom error classes with additional properties and methods. It is similar to extendable-error but offers more flexibility in defining custom error properties.
The es6-error package is another library for creating custom error classes by extending the built-in Error class. It is similar to extendable-error but focuses on providing a minimal and straightforward approach to creating custom errors.
The verror package allows for the creation of custom error classes with support for error wrapping and nested errors. It provides more advanced features compared to extendable-error, making it suitable for complex error handling scenarios.
A simple abstract extendable error class that extends Error
, which handles the error name
, message
and stack
property.
npm install extendable-error --save
import ExtendableError from 'extendable-error';
class SomeError extends ExtendableError {
constructor(
message: string,
public code: number
) {
super(message);
}
}
let someError = new SomeError('Some error', 0x0001);
MIT License.
FAQs
A simple extendable error class that extends Error.
The npm package extendable-error receives a total of 737,840 weekly downloads. As such, extendable-error popularity was classified as popular.
We found that extendable-error demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.