AJAX和Facebook API

Let's say I want to use this:

$.ajax({
  url: apiUrl,
  success: function(result) {
    $.each(result, function(key, val) {
      var shareCount = val["share"]["share_count"];
      if (shareCount > 0) {
        setTimeout(function() {
        // Do something
        }, 0000);
      } else {
        setTimeout(function() {
        // Do something else
        }, 0000);
      }
    });
  }
});

Which would get a like count from Facebook. Now what if the API is down / the visitor can't access it (unlikely, but what if) or throws back an error like:

{
 "error": {
    "message": "(#4) Application request limit reached",
    "type": "OAuthException",
    "is_transient": true,
    "code": 4,
    "fbtrace_id": ""
  }
}

How would I go about displaying an error message if either were to happen?

error: function(result)

Add an error-function to be called if the request fails for some reason

$.ajax({
  url: apiUrl,
  success: function(result) {
    $.each(result, function(key, val) {
      var shareCount = val["share"]["share_count"];
      if (shareCount > 0) {
        setTimeout(function() {
        // Do something
        }, 0000);
      } else {
        setTimeout(function() {
        // Do something else
        }, 0000);
      }
    });
  },
  error: function(error) {
    // Do something with the error message
    alert('There was a problem fetching likes from facebook');
  },
});