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

angular-errorz

v2.1.0

Published

An error handling service for AngularJS

Downloads

2

Readme

Angular-Errorz

GitHub version

An error handling service for AngularJS


Features

  • Unique handling of each HTTP status code
  • Batch handling of HTTP status codes
  • Prevents handled errors from bubbling up (no unexpected errors in dependencies -- like promises)
  • Configurable flood control to prevent spamming of duplicate errors

Quick Start

AngularJS ~1.2 is required

Installation

npm install angular-errorz

Add module reference

var exampleApp = angular.module("exampleApp", ["ttErrorz"]);

Configuration

Configure the service within your app module's run block:

exampleApp.run(["errorz", function (errorz) {
    errorz.addHandler(/* see Examples */);
}]);

Functions

addHandler(status, handler)

Add a handler for an HTTP status code

Arguments

| Param | Type | Details | |---------|----------|------------------------------------------------------------------------------------| | status | Number | The HTTP status code to handle. | | handler | Function | The function the service should call when handling the specified HTTP status code. |

Returns

errorz: for chaining.

addBatch(statuses, handler)

Add a handler for multiple HTTP status codes

Arguments

| Name | Type | Details | |----------|----------|---------------------------------------------------------------------------------------| | statuses | Array | The HTTP status codes to handle. | | handler | Function | The function the service should call when handling the specified HTTP status codes. |

Returns

errorz: for chaining.

handled(status)

Determines whether the service has been configured to handle the specified status

Arguments

| Param | Type | Details | |--------|--------|--------------------------------| | status | Number | The HTTP status code to check. |

Returns

Boolean: true when the service contains a handler for the specified status.

statusCodes()

Gets the list of HTTP status codes the service has been configured to handle.

Arguments

None

Returns

Array[String]: an array of HTTP status codes.

Properties

| Name | Type | Details | |------------------------|--------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | floodControl.threshold | Number | The number of milliseconds the service will wait before calling handlers for identical HTTP status codes. Setting this to undefined, null, or 0 will disable Flood Control. Defaults to 1000. |

Examples

1. Handle server error 500

Capture HTTP status code 500, and output the error to the browser's console.

errorz.addHandler(500, function (rejection) {
    console.error("Please try again.", "Server Error 500");
});

2. Handle multiple server errors

Capture HTTP status codes: -1, 0, 500, using the same handler for all of them. Outputting the error to the browser's console.

errorz.addBatch([-1, 0, 500], function (rejection) {
    console.error("Please try again.", "Server Error " + rejection.status);
});

You can do the same thing with multiple calls to addHandler instead of addBatch. Impractical, for this use case, but here it is for demonstrative purposes:

errorz.addHandler(-1, handler)
    .addHandler(0, handler)
    .addHandler(500, handler);

var handler = function (rejection) {
    console.error("Please try again.", "Server Error " + rejection.status);
};

3. Handle server errors conditionally

Similar to Example 2, but handle HTTP status code 404 conditionally within the same handler.

errorz.addBatch([-1, 0, 404, 500], function (rejection) {
    rejection.status === 404 && console.warn(rejection.config.url, "404 Not Found")
        || console.error("Please try again.", "Server Error " + rejection.status);
});

4. Add a handler after the fact

Effectively the same end result as Example 3, just spread out.

errorz.addBatch([-1, 0, 500], function (rejection) {
    console.error("Please try again.", "Server Error " + rejection.status);
});

Then, elsewhere/elsewhile...

errorz.addHandler(404, function(rejection) {
    console.warn(rejection.config.url, "404 Not Found");
});

5. Handle server errors (with toast)

Same as Example 3, but notify the user with toastr instead of logging to the console. We also enable flood control with a threshold equal to toastr's timeout, to prevent spamming the user with toast when there is a flood of identical errors.

errorz.addBatch([-1, 0, 404, 500], function (rejection) {
    rejection.status === 404 && toastr.warning(rejection.config.url, "404 Not Found")
        || toastr.error("Please try again.", "Server Error " + rejection.status);
}).floodControl.threshold = +toastr.options.timeOut;