'use strict';

(function(angular, app) {

  /**
   * Builds the error message for the given error.
   *
   * @param {Object} error The promise error as returned by the interceptor
   * @param {Object} $filter Angular filter
   * @return {String} The translated error message
   */
  function getErrorMessage(error, $filter) {
    var errorCode;
    var errorModule;

    if (error.data && error.data.error) {
      errorCode = error.data.error.code;
      errorModule = error.data.error.module;
    }

    // Not authorized
    if (error.status === 403)
      return $filter('translate')('CORE.ERROR.FORBIDDEN');

    // Probably a client application error
    else if (error.status === 400)
      return $filter('translate')('CORE.ERROR.CLIENT') + ' (code=' + errorCode + ', module=' + errorModule + ')';

    // Internal server error
    else if (errorCode && errorModule)
      return $filter('translate')('CORE.ERROR.SERVER') + ' (code=' + errorCode + ', module=' + errorModule + ')';

    // Other error
    else
      return $filter('translate')('CORE.ERROR.SERVER');
  }

  /**
   * Defines an HTTP interceptor to handle all application errors.
   *
   * Not authorized errors (401) logs out the user while the other HTTP errors set an error message
   * using an alert.
   */
  function ErrorInterceptor($rootScope, $filter, $q) {
    return {
      responseError: function(rejection) {

        // No authentified
        if (rejection.status === 401)
          $rootScope.$broadcast('forceLogout');
        else if (rejection.status !== -1 &&
          !(rejection.config && (rejection.config.timeout ||
            rejection.config.timeout.status))) // if not canceled
          $rootScope.$broadcast('setAlert', 'danger', getErrorMessage(rejection, $filter), 0);

        return $q.reject(rejection);
      }
    };
  }

  app.factory('errorInterceptor', ErrorInterceptor);
  ErrorInterceptor.$inject = ['$rootScope', '$filter', '$q'];

})(angular, angular.module('ov'));

@@ -1560,10 +1560,17 @@
     
+       (
 !
-(
 reje
@@ -1586,12 +1586,12 @@
 fig 
-&& (
+%7C%7C !
 reje
@@ -1613,29 +1613,18 @@
 meout %7C%7C
-%0A           
  
+!
 rejectio
@@ -1652,28 +1652,8 @@
 us))
-) // if not canceled
 %0A   

Fix bug on AngularJS ErrorInterceptor when request failed