Sha256: 3c38ae0e3ac318ee47252e668dd022363eca0af7d88eade1a1405fa4c2e23723

Contents?: true

Size: 1.9 KB

Versions: 134

Compression:

Stored size: 1.9 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, Notification) {
        function handleError(response, $scope, defaultErrorMessage) {
            if (response.hasOwnProperty('data') && response.data.hasOwnProperty('errors')) {
                angular.forEach(response.data.errors, function (error) {
                    Notification.setErrorMessage(error);
                });
            } else if (response.hasOwnProperty('data') && response.data.hasOwnProperty('error') && response.data.error.hasOwnProperty('message')) {
                Notification.setErrorMessage(response.data.error.message);
            } else {
                Notification.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);
        };

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

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

Version data entries

134 entries across 134 versions & 1 rubygems

Version Path
katello-4.3.1 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.4.0 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.4.0.rc2 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.4.0.rc1 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.2.2 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.3.0 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.3.0.rc4 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.3.0.rc3 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.3.0.rc2.1 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.3.0.rc2 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.3.0.rc1 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.2.1 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.2.0.1 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.1.4 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.0.3 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.2.0.1.rc3 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-3.18.5 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.2.0.1.rc2 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.2.0.rc2 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.1.3 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js