Fix steal.request to handle negative status codes and IE exceptions. #56

Merged
merged 1 commit into from Jan 19, 2012
Jump to file or symbol
Failed to load files and symbols.
+7 −5
Split
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 ||

This comment has been minimized.

Show comment Hide comment
@snesin

snesin Dec 6, 2011

Safari generates negative request.status codes with missing URLs on file:// requests.

@snesin

snesin Dec 6, 2011

Safari generates negative request.status codes with missing URLs on file:// requests.

(request.status === 0 && request.responseText === '') ) {
- error && error();
+ error && error(request.status);

This comment has been minimized.

Show comment Hide comment
@snesin

snesin Dec 6, 2011

If the URL errors, pass the request.status code to error to allow for branch handing based on type (404 vs 500 etc).

@snesin

snesin Dec 6, 2011

If the URL errors, pass the request.status code to error to allow for branch handing based on type (404 vs 500 etc).

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();
+ }

This comment has been minimized.

Show comment Hide comment
@snesin

snesin Dec 6, 2011

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 afterwards. 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 being thrown by calling the already nulled clean method again.

@snesin

snesin Dec 6, 2011

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 afterwards. 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 being thrown by calling the already nulled clean method again.

}
};