HTML and CSS Reference
In-Depth Information
}
});
So far, you have passed only one function to the then function of the promise. The then function
invokes the first passed function when the request completes successfully. The completed function
receives the response from the server as its single argument.
As you can see from the prototype, however, you can also pass a second function to the promise.
That second function is the error handler for the request. The error handler function will be invoked
automatically by the system if the request fails for some reason. The error function receives an error
object, which has properties such as status , statusTex t, and message . Note that depending on which
error occurred, some of these properties may not be set. You might want to use a generic message
such as the one below and depicted in Figure 11-2.
WinJS.xhr({ url: rssReaderApp.Feed }).then(
function (response) {
rssReaderApp.parseFeed(response);
},
function (error) {
rssReaderApp.alert("A download error occurred.");
}
);
FIGURE 11-2 Handling errors during HTTP operations.
Search WWH ::




Custom Search