Skip to content

Angular module that displays JavaScript window.onerror errors to the end user using toastr. Only displays the message if the URL is localhost, so that it doesn't impact your QA or production users.

License

joehoppe/angular-errors-on-toast

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

angular-errors-on-toast

Ever forget to open the console window while developing JavaScript? I know it's a cardinal sin, but once and a while I forget. I'm human.

I wondered: can I use window.onerror to let me know that there are JavaScript runtime errors, in case I forget to open the console?

I could use an alert() box, but those are obtrusive and annoying.

Then I then thought of using Toaster. It's a great library that flashes a message in a preconfigured corner of the window. The message briefly appears before going away.

Angular-Errors-On-Toast is my Angular module solution.

Audience

Will my end users see these messages? No. It's configured to display these errors only when the domain is localhost. I'll make this configurable in the future. You can modify the source code in the meantime.

How to get it

  1. bower install angular-errors-on-toast#0.1
  2. Change exceptionHandler.js

How to set it up

Replace "app" with the name of your AngularJS application.

I.e.:

  angular.module("app1").factory("$exceptionHandler", function ($injector) {
    ...
  });

Want the app to work for a URL other than localhost?

In errorsOnToast.js, change the array of allowedURLs to have the correct URL(s). I.e.:

var allowedUrls = ["localhost", "example.com"];

Requires

  1. Angular 1.3
  2. angular-toastr 0.1

What does it look like?

This briefly flashes in the corner of the window before going away.
![alt tag](https://raw.githubusercontent.com/joehoppe/angular-errors-on-toast/master/readme/error.PNG)

License

MIT

I can do a lot more with this. Please let me know if you are interested.

About

Angular module that displays JavaScript window.onerror errors to the end user using toastr. Only displays the message if the URL is localhost, so that it doesn't impact your QA or production users.

Resources

License

Stars

Watchers

Forks

Packages

No packages published