Gianluca Ghettini Gianluca Ghettini - 6 months ago 10
Javascript Question

$Http.get(), how to deal with 404 response from WebAPI

On my web application I perform a

GET
command to a remote HTTP WebAPI service

$http.get(url).then(function(data) { do_something(); });


everything works fine when the WebAPI returns some data, however the function doesn't seem to trigger when the WebAPI return a 404 error (no data to display).
How can I set a callback for it?

Answer
$http.get(url).then(function(data) {
  do_something();
}, function(err) {
  // your error function
});
Comments