Permalink
Browse files

Updated steal.request to handle negative status codes and IE exceptions.

1) Check for request.status<0 to call error instead of success. Safari generates negative request.status codes with missing URLs on file:// requests. 
2) Make sure clean has not already been called in catch. If the request.status is 2 (missing file), error and clean will be called from the check function. In IE, an exception is also thrown. Make sure that clean and error have not already been called from check to prevent duplicate call to error for same request, and prevent an exception from begin thrown by calling the nulled clean method again.
3. If the URL errors, pass the request.status code to error to allow for branch handing based on type (404 vs 500 etc).
  • Loading branch information...
1 parent 3c3f6e8 commit 95757756f10210c55bc64220d0790eaf72daff74 @snesin snesin committed Dec 6, 2011
Showing with 7 additions and 5 deletions.
  1. +7 −5 steal.js
View
@@ -1462,9 +1462,9 @@ request = function(options, success, error){
check = function(){
if ( request.readyState === 4 ) {
if ( request.status === 500 || request.status === 404 ||
- request.status === 2 ||
+ request.status === 2 || request.status < 0 ||
(request.status === 0 && request.responseText === '') ) {
- error && error();
+ error && error(request.status);
clean();
} else {
success(request.responseText);
@@ -1487,9 +1487,11 @@ request = function(options, success, error){
request.send(null);
}
catch (e) {
- console.error(e);
- error && error();
- clean();
+ if (clean) {
+ console.error(e);
+ error && error();
+ clean();
+ }
}
};

0 comments on commit 9575775

Please sign in to comment.