Monday, January 9th, 2006
Using the error codes from XHR calls
<>p>Over at The Form Assembly they are discussing Treating the HTTP Status code right.The main point of the article is the discussion of trapping various status codes, and doing smart things with them.
For example, a smart authentication handler could look something like:
switch (req.status) {
case 200:
// login ok, moving on...
break;
case 201:
// was a registration.. will show a welcome message.
showWelcomeMessage(req.reponseText);
break;
case 403:
// authentication problem. The error message is in responseText
showErrorMessage(req.responseText);
break;
default:
// unknown error
alert('There was a problem..');
}
Of course, there are browser quirks with status codes too, which is why you will see the following in the Prototype code:
responseIsSuccess: function() {
return this.transport.status == undefined
|| this.transport.status == 0
|| (this.transport.status >= 200 && this.transport.status < 300);
}
Related Content:











Leave a comment