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 🙏

© 2024 – Pkg Stats / Ryan Hefner

wix-error-boundaries

v1.0.372

Published

Bounding errors by scope or context of running code

Downloads

41

Readme

Wix Error Boundaries

In many cases, when errors thrown in our code, we want to handle them properly. Sometimes we want to apply an algorithms to resolve the error, in other cases we would like to report them to an external system or maybe just throw again and bubble them up.

Error handling become even more complicated when your app is living under another app context and those two apps may communicate. In this case, errors might be thrown on both sides and then you might be mislead by handling not-yours errors.

Bounding errors by scope or context of the actual running code is crucial when working on mixed app content environment. By using wix-error-boundaries, applying such methodology will be easy for you to bound your errors the way you see fit and handle them according to the errors' scope and the way you see fit.

Install

npm install -save wix-error-boundaries

Usage

import errorBoundaries from 'wix-error-boundaries'

The errorBoundaries function accept the following parameters:

  • scopes - an Array of strings which represents the scopes you'd like to bound between
  • errorHandler - a Function with the signature (error, scope), where error is the thrown Error object and scope is the scope the error happened

For the following example, let's assume got an API with functions called foo and fireErrorEvent.

Now, let's define some scopes:

const MY_SCOPE = 'myCodeZone'
const OTHER_SCOPE = 'otherCodeZone'

and initialize the error boundaries with our errorHandler:

const {myCodeZone, otherCodeZone} = errorBoundaries({
	scopes: [MY_SCOPE, OTHER_SCOPE],
	errorHandler: (error, scope) => {
		switch(scope){
			case MY_SCOPE: // do something with my error
				reportToSystem(error)
				break;
			case OTHER_SCOPE: // not my scope so let's do something else
				fireErrorEvent(error)
				break;
			default:
				throw error
		}
	}
})

Pay attention that the returned object of errorBoundaries is actually containing the scopes as keys. Each key value is a wrapping function that will be bound to that certain scope.

Next, to use those wrappers you can do the following

const scopedFoo = otherCodeZone(foo)
.
.
.

// safely executing 'foo' while its scoped
scopedFoo()

In case foo throws an exception, it will be handled in errorHandler according to the error scope!

Have Fun!