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

Merged
merged 1 commit into from Jan 19, 2012

Conversation

Projects
None yet
2 participants
Contributor

snesin commented Dec 6, 2011

  1. Check for request.status<0 to call error instead of success. Safari generates negative request.status codes (-1100) 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 afterwards. In catch, 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 from a call to the already nulled clean method.
  1. If the URL errors, pass the request.status code to error to allow for branched handing based on type (404 vs 500 etc).
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).
@@ -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 ||
@snesin

snesin Dec 6, 2011

Contributor

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

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

snesin Dec 6, 2011

Contributor

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

+ console.error(e);
+ error && error();
+ clean();
+ }
@snesin

snesin Dec 6, 2011

Contributor

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.

polgfred added a commit that referenced this pull request Jan 19, 2012

Merge pull request #56 from snesin/master
Fix steal.request to handle negative status codes and IE exceptions.

@polgfred polgfred merged commit ca5ff9b into stealjs:master Jan 19, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment