R
R
Ramil Z.2015-11-26 11:16:59
Angular
Ramil Z., 2015-11-26 11:16:59

Where to enter the function if the result of $save in Angular $resource is 422 response (instead of 200)?

I call the standard $save method of ng-resource. If the response from the server is 200 , then everything is fine and we get into the then method . If the response is 422 (validation failed), then does not work at all.
How to be? Where to enter the function in case of error, when the response code is different from 200?

masterOrder.$save().then(function (data) {
                if (data.$resolved == true) {
                    $scope.acceptSuccess = true;
                    alertOptions.content = data.flash.message;
                    alertOptions.type = data.flash.class;
                    $alert(alertOptions);
                    $anchorScroll();
                } else {
                    alert('failed');
                }
            });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2015-11-26
@proteye

You need to improve knowledge on promises : then the second argument is the error handler. There is also a catch method that catches all errors in general.
True, I don’t know Angular, perhaps there are special curves there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question