Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
@forward-steady/exception
Advanced tools
An Exception base class for Javascript/Typescript that extends the built-in Error class with code and context properties.
An Exception base class for Javascript/Typescript that extends the built-in Error class with code and context properties.
For npm users:
npm install @forward-steady/exception
for yarn users:
yarn add @forward-steady/exception
The Exception class derives from the Error class and can be use in a similiar manner. It includes optional code and context properties that can be provided in the constructor.
const message = 'Unable to perform action X';
const code = 'action-x-failed';
const context = {
recordId: 5003
}
throw new Exception(message, code, context);
Since the Exception class derives from the Error class, it will have a stack property just as an Error instance would.
const exception = new Exception(message, code, context);
console.log(exception.stack)
It is also easy to convert an Error instance into an Exception instance and preserve the message and stack trace of the error. This allows a code and context to be include with the error message and stack trace.
const error = new Error(message)
const exception = Exception.fromError(error, code, context);
expect(exception.message).toBe(error.message);
expect(exception.stack).toBe(error.stack);
expect(exception.code).toBe(code);
expect(exception.context).toBe(context);
FAQs
An Exception base class for Javascript/Typescript that extends the built-in Error class with code and context properties.
The npm package @forward-steady/exception receives a total of 0 weekly downloads. As such, @forward-steady/exception popularity was classified as not popular.
We found that @forward-steady/exception 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
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.