Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to stop execution if one of the tasks failed?
Message
 
 
À
28/03/2018 13:56:39
Information générale
Forum:
Javascript
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01659020
Message ID:
01659049
Vues:
28
>>I was thinking about it, but that was developed by other developer and he probably had a reason to make all of them as separate functions and sometimes call all of them (in the initial load) and sometimes just one of them.
>
>So how is the promise handled in each of the methods ?

In all of these methods in the then portion there are some other code executed. It is rather convoluted. In any case, I added a flag in the Load method and changed the code the way you suggested.

I am still seeing some weird behavior :(

We have a directive which we use in every edit form and that is supposed to properly handle server errors. I can not figure out why the code in this directive is being called twice :(

The app.js has the following code:
app.factory('badRequestInterceptor', ['$rootScope', '$q', function ($rootScope, $q) {
        return {
            'responseError': function (rejection) {
                if (rejection.status === 400) {
                    $rootScope.$broadcast("sm:badRequest", rejection.data);
                }
                return $q.reject(rejection);
            }
        };
    }]);
Similar code for other types of errors.

And the directive to react on that event is:
return {
            restrict: 'A',
            controller: ['$scope', '$timeout', function ($scope, $timeout) {
                log = $log.getInstance("serverError");

                var errorToastConfig = {
                    closeButton: true,                    
                    tapToDismiss: true
                };

                var title = resourceFactory.getResource("Messages", "applicationError");

                $scope.$on('sm:badRequest', function (event, data) {
                    $timeout(function () {
                        spinnerService.stopSpinner();
                    }, 0);
                    if (!$scope.errorHandled && !$scope.showForm) {
                        log.debug("Handling bad request");
                        let errorMsg = "";
                        angular.forEach(data, function (value, key) {
                            if (value.message == '') value.message = 'The ' + value.property + ' value is invalid.'
                            errorMsg = errorMsg + value.message + " ";
                        });
                        
                        errorMsg = errorMsg.trim();
                        $scope.errors = data;                       
                        
                        if (errorMsg=="")
                            errorMsg = resourceFactory.getResource('Messages', 'errorOnForm');

                        title = resourceFactory.getResource("Messages", "badRequest");
                        toastr.remove();
                        toastr.error(errorMsg, title, errorToastConfig);

                    }
                    $scope.disableAction = false;
                });
The edit form has this directive, e.g.
<form name="form" novalidate role="form" 
          sm-dirty-check on-ok="dirtyOk()" 
          server-error ng-hide="!showForm" class="ng-cloak">
So, when I throw an error from my API controller, I see in Developer's console red error about bad request and then two 'Handling Bad Request' messages. I can not figure out why do I have two of them and not just one.

Do you have any idea what may be wrong in that scenario?
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform