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.15.0.rc2 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.15.0.rc1 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.14.1 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.14.0 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.14.0.rc3 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.14.0.rc2 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.14.0.rc1.1 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.14.0.rc1 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.13.1 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.13.0 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.12.1 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.13.0.rc1 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.12.0 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.12.0.rc3 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.12.0.rc2 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.12.0.rc1 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.11.1 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.11.0 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.11.0.rc2 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js
katello-4.11.0.rc1 engines/bastion_katello/app/assets/javascripts/bastion_katello/common/api-error-handler.service.js