equal
deleted
inserted
replaced
497 }) |
497 }) |
498 }; |
498 }; |
499 |
499 |
500 Response.error = function() { |
500 Response.error = function() { |
501 var response = new Response(null, {status: 200, statusText: ''}); |
501 var response = new Response(null, {status: 200, statusText: ''}); |
|
502 response.ok = false; |
502 response.status = 0; |
503 response.status = 0; |
503 response.type = 'error'; |
504 response.type = 'error'; |
504 return response |
505 return response |
505 }; |
506 }; |
506 |
507 |
542 xhr.abort(); |
543 xhr.abort(); |
543 } |
544 } |
544 |
545 |
545 xhr.onload = function() { |
546 xhr.onload = function() { |
546 var options = { |
547 var options = { |
547 status: xhr.status, |
|
548 statusText: xhr.statusText, |
548 statusText: xhr.statusText, |
549 headers: parseHeaders(xhr.getAllResponseHeaders() || '') |
549 headers: parseHeaders(xhr.getAllResponseHeaders() || '') |
550 }; |
550 }; |
|
551 // This check if specifically for when a user fetches a file locally from the file system |
|
552 // Only if the status is out of a normal range |
|
553 if (request.url.indexOf('file://') === 0 && (xhr.status < 200 || xhr.status > 599)) { |
|
554 options.status = 200; |
|
555 } else { |
|
556 options.status = xhr.status; |
|
557 } |
551 options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL'); |
558 options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL'); |
552 var body = 'response' in xhr ? xhr.response : xhr.responseText; |
559 var body = 'response' in xhr ? xhr.response : xhr.responseText; |
553 setTimeout(function() { |
560 setTimeout(function() { |
554 resolve(new Response(body, options)); |
561 resolve(new Response(body, options)); |
555 }, 0); |
562 }, 0); |
561 }, 0); |
568 }, 0); |
562 }; |
569 }; |
563 |
570 |
564 xhr.ontimeout = function() { |
571 xhr.ontimeout = function() { |
565 setTimeout(function() { |
572 setTimeout(function() { |
566 reject(new TypeError('Network request failed')); |
573 reject(new TypeError('Network request timed out')); |
567 }, 0); |
574 }, 0); |
568 }; |
575 }; |
569 |
576 |
570 xhr.onabort = function() { |
577 xhr.onabort = function() { |
571 setTimeout(function() { |
578 setTimeout(function() { |