var ctlMod = angular.module( "sparkCoreBrowserApp.controllers", [] );


ctlMod.controller( "Main", [ "$scope", "$rootScope", "$location",
    function ( $scope, $rootScope, $location ) {

        $scope.isActiveNavItem = function ( view ) {

            return view === $location.path();

        };

        $scope.$on( "error", function ( e, args ) {

            $scope.errorMessage = args.message;

        } );

        $scope.$on( "authSuccess", function () {

            $location.path( "/devices" );

        } );

    } ] );


ctlMod.controller( "Login", [ "$scope", "$rootScope", "$window", "Spark",
    function ( $scope, $rootScope, $window, Spark ) {

        $scope.submitted = false;

        var loginCallback = function ( err, data ) {

            if ( err ) {
                return $rootScope.$broadcast( "error", {
                    message: err.data.error_description
                } );
            }
            $window.sessionStorage.token = data.access_token;
            return $rootScope.$broadcast( "authSuccess" );

        };

        $scope.login = function () {

            if ( $scope.loginForm.$valid ) {
                return Spark.authenticate( {
                    username: $scope.username,
                    password: $scope.password
                }, loginCallback );
            }

        };

    } ] );


ctlMod.controller( "Devices", [ "$scope", "$rootScope", "Spark",
    function ( $scope, $rootScope, Spark ) {

        Spark.devices( function ( err, data ) {
            if ( err ) {
                console.log( err );
                return $rootScope.$broadcast( "error", {
                    message: err.data.error_description
                } );
            }

            $scope.devices = data;
        } );

    } ] );

@@ -1399,27 +1399,22 @@
 %22, %22
-$rootScope%22, %22Spark
+Spark%22, %22Error
 %22,%0A 
@@ -1439,25 +1439,20 @@
 pe, 
-$rootScope, Spark
+Spark, Error
  ) %7B
@@ -1546,84 +1546,28 @@
     
-console.log( err );%0A                return $rootScope.$broadcast
+return Error
 ( 
-%22
 err
-or%22, %7B
+ );
 %0A   
@@ -1571,32 +1571,35 @@
             
+%7D%0A%0A
         
 message: err
@@ -1590,91 +1590,59 @@
     
-message: err.data.error_description%0A                %7D );%0A            %7D%0A%0A           
+    $scope.devices = data;%0A            console.log(
  $sc
@@ -1645,38 +1645,33 @@
  $scope.devices 
-= data
+)
 ;%0A        %7D );%0A%0A

Use error handler