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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@smbcheeky/error-object

v1.2.0

Published

Create errors that can be both thrown and returned. Make error handling easier for both JavaScript and TypeScript.

Downloads

706

Readme

License deno.bundlejs.com npm downloads GitHub last commit GitHub stars

Installation

npm install @smbcheeky/error-object

yarn add @smbcheeky/error-object

Description

The ErrorObject class is made to extend Error enabling type guard checks like errorObject instanceof Error, errorObject instanceof ErrorObject, ErrorObject.is() and isErrorObject(). The ErrorObject class is backwards compatible with Error and introduces a few new features:

  • It can be thrown or returned, you choose.
  • It can be valid only if it contains a code and a message values
  • Intuitive type guards which help narrow down the type of JS objects
  • It can have a numberCode, not just a string code
  • set default values for the generic error objects via ErrorObject.DEFAULT_GENERIC_CODE and ErrorObject.DEFAULT_GENERIC_MESSAGE
  • set a default domain for all errors via ErrorObject.DEFAULT_DOMAIN
  • Use ErrorObject.generic() or ErrorObject.withTag('TAG') to create an error from thin air
  • Use .isGeneric(), and .hasTag() to check if the error is a generic error or has a specific tag
  • Chain call setters like .setCode(), .setNumberCode(), .setMessage(), .setDetails(), .setDomain(), .setTag() to modify the error object at any moment
  • Setters can receive a value or a transform function, facilitating access to the current value while you modify the property
  • Chain logs like .log(tag), .debugLog(tag), .verboseLog(tag) to log information about the error object inline
  • Use .description() or .toString() to get a human-readable description of the error
  • Use details, domain and tag to customize the error object and help easily distinguish between different errors

Override default log method (default is console.log)

To override the default log method, set the static property LOG_METHOD to a function that accepts any number of arguments and returns nothing. The default log method is console.log.

Override default generic error code and message

To override the default generic error code and message, set the static properties GENERIC_CODE and GENERIC_MESSAGE.

new ErrorObjectFromPayload(payload, options)

To parse errors from any payload, check out @smbcheeky/error-object-from-payload.

Usage & Examples

You can find examples in the playground file.

new ErrorObject({
  code: "",
  message: "Something went wrong.",
  domain: "auth",
}).debugLog("LOG");

// [LOG] Something went wrong [auth]
// {
//   "code": "",
//   "message": "Something went wrong",
//   "domain": "auth"
// }
const foo = (): { success: true } | ErrorObject => {
  return { success: true };
};

const fooError = (): { success: true } | ErrorObject => {
  return ErrorObject.generic();
};

const result1 = foo();
if (isErrorObject(result1)) {
  result1;
  result1.code;
  console.log("result1 is ErrorObject");
  return;
}
result1;
// result1.code; // triggers a type error
console.log("result1 is not ErrorObject");

const result2 = foo();
if (result2 instanceof ErrorObject) {
  result2;
  result2.code;
  console.log("result2 is ErrorObject");
  return;
}
result2;
// result2.code; // triggers a type error
console.log("result2 is not ErrorObject");

const result3 = fooError();
if (ErrorObject.is(result3)) {
  result3;
  result3.code;
  console.log("result3 is ErrorObject");
  return;
}
result3;
// result3.code; // triggers a type error
console.log("result3 is not ErrorObject");