Error Handling using $resource

3,263 views
Skip to first unread message

lightscalar

unread,
Nov 9, 2011, 11:33:47 AM11/9/11
to AngularJS
Cannot seem to find documentation on how to handle errors using
$resource.

Suppose I build a resource that attempts to save a new user, but
(server-side) validation fails because the user name is not unique,
for instance. How can I handle the error response. Can I access an
error callback from $resource somehow? Right now it seems to log the
error to the console.

Thanks,

Igor Minar

unread,
Nov 9, 2011, 12:49:12 PM11/9/11
to ang...@googlegroups.com
all resource methods take two arguments - success callback and error callback. You can use the latter for error handling.

/i


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.


lightscalar

unread,
Nov 9, 2011, 1:44:48 PM11/9/11
to AngularJS
Ah! Got that working now... was looking in the wrong parts of the
documentation. Thanks!

-mjl

Murali Vasudevan

unread,
Apr 23, 2013, 9:00:20 PM4/23/13
to ang...@googlegroups.com
Igor,

I have tried using error callback both as function args as well as .success vs .error paradigm and the error callback never gets invoked.

The behavior is consistent on $resource as well as $http.

For example I used $http as below

            $http.jsonp(url)
                .success(function(data){
                    console.log(data.found);
                })
                .error(function(data){
                    console.log('on error');
                });


and $resource as below

var result = service.query(param, data, function (response) {
                console.log('on success ');
            },
            function (response) {
                console.log('on error ');
            });

This was tried on version 1.0.6 and 1.1.4 and i had no luck with either of those.

Thanks

Murali
Reply all
Reply to author
Forward
0 new messages