Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Proper rejection
Message
 
 
General information
Forum:
AngularJS
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01653655
Message ID:
01653672
Views:
36
>>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.

Yes, it's a simple wrapper
/**
         * @var $http Http
         * @type Object
         */
        Object.defineProperty(this,
            "Http",
            {
                enumerable: true,
                get: function() {
                    return $injector.get("$http");
                }
            });
My colleague adjusted all our services to the code I showed. Do you mean that code is incorrect and needs to be fixed to return error instead?


>>What if I want to catch the error in the controller instead?
>
>Simply catch the rejected promise at that level instead.
>

Yes, that's what I will do.

>
>>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.

I've been thinking that perhaps for my custom exception I will just return the message using OK(message = myErrorMessage) and will use my controller's code this way. But I'll ponder on this idea a bit.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform