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-invocation-handler

v1.5.1

Published

Enables general error handling and logging which allows to log errors, e.g for automatically sending back to the backend or for showing to the user

Downloads

10

Readme

Angular Invocation Handler

Build Status Build status Bower version npm version Code Climate  NPM devDependency Status

A module for collecting errors, stack traces and other information globally from within your Angular app e.g. for saving to a remote service or for displaying

NPM

Feel free to donate

Or donate Bitcoins: Bitcoin

Also via greenaddress

Reasons to use

It's anyoing to handle all errors in controller and service and also very defective. So instead of surfacing the log it would be cool to manage them at a central place and maybe store them via on a backend service

WIP

  • [x] Library core
  • [x] Write unit tests
  • [x] NPM package
  • [ ] Write e2e-tests
  • [ ] Write an API doc
  • [ ] Provide complete examples

Usage

Install this module:

bower install angular-invocation-handler --save

Add the dependencies

/*global app: true*/
var app = angular.module('resourcesApp', [
...
'ngIH.core',
'ngIH.ui' /* optional */,
'ngIH.exceptionHandler' /* optional */
]);

If you like to display the error message within your app, also include the ui module.

Configure the service to be handled:

app.config(function ($provide, ngIHServiceProvider, ngIHConfig) {
  'use strict';

  // enable UI feedback attach, default false
  ngIHConfig.feedbackAttach = true;
  // enable clearing of feedback
  ngIHConfig.feedbackClear = true;
  // set custom selector for appending UI error display element
  ngIHConfig.uiSelector = '.navbar';
  // enable scrolling to error display element
  ngIHConfig.scrollToError = true;
  // redirect to static error pages, e.g. 404 --> /404.html, default false
  ngIHConfig.redirect = true;
  // adding custom error handler, default is disabled
  ngIHConfig.customErrorHandler = 'errorHandlingService';
  // decorate the mentioned [services] with automatic error handling.
  ngIHServiceProvider.decorate($provide, ['eventService']);
});

The customized error handling service looks like this:

app.factory('errorHandlingService', function ($log, $translate, blockUI) {
    'use strict';

    function buildValidationMessages(error, msg, callback, i) {
        var errorDetails = error.data[i];
        $translate('VALIDATION_ERROR_' + errorDetails.messageTemplate).then(function (translatedValue) {
            msg = msg + ' ' + translatedValue;

            // replace placeholder if set
            if (errorDetails.propertyList) {
                msg = msg.format(errorDetails.propertyList);
            }

            // callback when complete
            if (i === error.data.length - 1) {
                $log.debug(error.status + '=>' + msg);
                callback(msg);
            }
        }, function (err) {
            $log.error(err);
            callback(msg);
        });
    }

    return {
        resolve: function (details, callback) {
            if (details.error) {
                var error = details.error;
                // read by http code
                $translate('HTTP_STATUS_CODE_' + error.status).then(function (translatedValue) {
                    var msg = translatedValue;
                    // handle violation errors
                    if (error.status === 400 && error.data && error.data.length) {
                        for (var i = 0; i < error.data.length; i++) {
                            blockUI.stop();
                            buildValidationMessages(error, msg, callback, i);
                        }
                    } else {
                        blockUI.stop();
                        $log.debug(error.status + '=>' + msg);
                        callback(msg);
                    }
                });
            }
        }
    };
});

About

This module instruments Angular's interceptors to invoke a configurable set for the error handling.