Sha256: 7755fbc2f65f66a871a24a2997664a3648930048001ca067c60100267edc80dc

Contents?: true

Size: 1.87 KB

Versions: 5

Compression:

Stored size: 1.87 KB

Contents

(function () {
    'use strict';

    /**
     * @ngdoc service
     * @name  Bastion.common.service:ApiErrorHandler
     *
     * @description
     *   Provides common functionality in handling Katello/Foreman API Errors.
     */
    function ApiErrorHandler(translate, GlobalNotification) {
        function handleError(response, $scope, defaultErrorMessage) {
            var hasScopeErrorMessages = $scope && $scope.hasOwnProperty('errorMessages');

            if (response.hasOwnProperty('data') && response.data.hasOwnProperty('errors')) {
                if (hasScopeErrorMessages) {
                    $scope.errorMessages = response.data.errors;
                } else {
                    angular.forEach(response.data.errors, function (error) {
                        GlobalNotification.setErrorMessage(error);
                    });
                }
            } else {
                if (hasScopeErrorMessages) {
                    $scope.errorMessages = [defaultErrorMessage];
                } else {
                    GlobalNotification.setErrorMessage(defaultErrorMessage);
                }
            }

            if ($scope && $scope.hasOwnProperty('panel')) {
                $scope.panel.error = true;
            }
        }

        this.handleGETRequestErrors = function (response, $scope) {
            var defaultErrorMessage = translate('Something went wrong when retrieving the resource.');
            handleError(response, $scope, defaultErrorMessage);
        };

        this.handlePUTRequestErrors = function (response, $scope) {
            var defaultErrorMessage = translate('Something went wrong when saving the resource.');
            handleError(response, $scope, defaultErrorMessage);
        };
    }

    angular.module('Bastion.common').service('ApiErrorHandler', ApiErrorHandler);
    ApiErrorHandler.$inject = ['translate', 'GlobalNotification'];
})();

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
katello-3.5.0.rc1 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-3.4.5 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-3.4.4 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-3.4.2 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-3.4.1 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js