Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Proper rejection
Message
From
24/08/2017 09:35:10
 
General information
Forum:
AngularJS
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01653655
Message ID:
01653667
Views:
38
This message has been marked as a message which has helped to the initial question of the thread.
Likes (1)
>Hi everybody,
>
>In our services we now have the following code
>
>
> var deferred = services.Deferred;
>
>        services.Http.get("api/secRoles/" + id)
>            .then(function (data) {
>                deferred.resolve(data.data);
>            })
>            .catch(function (error, status) {
>                deferred.reject(status);
>            });
>
>        return deferred.promise;
>
>However, when I was testing the above I saw that the status was undefined while error contained the information including status. What is the correct way for the catch block and do we need it at all?

Without knowing what services.Http is it's not possible to answer that. If it's a simple wrapper around angular $http then only one parameter would be returned.

>What if I want to catch the error in the controller instead?

Simply catch the rejected promise at that level instead.


>Also, related question. If I want to throw an error from the API controller and properly handle it in the controller.js code, what is the best Error Code to return back? We do have server error directive in every form that traps the 500 error and some others and handles them by displaying in a toastr. For my own exception I want to by-pass that handling.

Take your pick or make up your own - angular $http (in 1.x - not 2) regards any Http status code outside of 200-299 range as being an error ......

>
>Thanks in advance.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform