0

How can I handle errors of the $resource angularjs?

The 422 error is returned, you can check in the second image

I'll put here two images, the first is the request, the second is the error on the console after the request. I can not find solution for this. I've looked on google and nothing.

Request:

http://gyazo.com/e1f123a957b9577bd8946d36762f44db

Console error:

http://gyazo.com/f2c0b086c58b96f89bb5019b82e1176c

My restservice.js code

app.factory('RestService', function($resource, $http) {
    return {
        customers: $resource(_CONFIG_REST + 'customers/:id'),
        users: $resource(_CONFIG_REST + 'users/:id')
    }
});

My create.js

app.controller('customers.create', function($scope, $state, toastr, RestService) {
    $scope.submit = function() {
        RestService.customers.save($scope.data, function(response) {
            toastr.success('The customer was added successfully');
        }, function() {
            toastr.error('An error has ocurred');
        });
    };
});
João Silva
  • 167
  • 2
  • 9

0 Answers0