top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

What are the ways to track the error in AngularJS?

0 votes
What are the ways to track the error in AngularJS?
posted Jan 30, 2017 by Navya

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

AngularJS provides a service called $exceptionHandler. It handles errors by capturing them and logging them to the console using the $log service, another AngularJS service that wraps up console.log() to make it safe to use if the console object doesn’t exist. Also, Angular tries to provide a cause along with the error to provide some additional context to what went wrong.

Here is the example

angular.module("YOUR_APP", [])
  .config(["$provide", function ($provide) {

    $provide.decorator("$exceptionHandler", ["$delegate", "$window", "myConfig", function($delegate, $window, myConfig) {
      return function (exception, cause) {
        if(myConfig.environment === "production") {
          $window.sessionStorage.log = $window.sessionStorage.log || [];
          $window.sessionStorage.log.append({ exception: exception, cause: cause });
        else {
          $delegate(exception, cause);
answer Feb 1, 2017 by Ranjith Havaldar
Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.