Sfoglia il codice sorgente

fixed handling of invalid resources

Gildas 7 anni fa
parent
commit
c3b10b1292
2 ha cambiato i file con 7 aggiunte e 8 eliminazioni
  1. 3 7
      lib/fetch/bg/fetch.js
  2. 4 1
      lib/single-file/single-file-browser.js

+ 3 - 7
lib/fetch/bg/fetch.js

@@ -69,13 +69,9 @@
 			xhrRequest.onerror = event => reject(new Error(event.details));
 			xhrRequest.onerror = event => reject(new Error(event.details));
 			xhrRequest.onreadystatechange = () => {
 			xhrRequest.onreadystatechange = () => {
 				if (xhrRequest.readyState == XMLHttpRequest.HEADERS_RECEIVED) {
 				if (xhrRequest.readyState == XMLHttpRequest.HEADERS_RECEIVED) {
-					if (xhrRequest.status >= 400) {
-						reject(new Error(xhrRequest.statusText || xhrRequest.status));
-					} else {
-						const headers = {};
-						headers["content-type"] = xhrRequest.getResponseHeader("Content-Type");
-						resolve({ xhrRequest, headers });
-					}
+					const headers = {};
+					headers["content-type"] = xhrRequest.getResponseHeader("Content-Type");
+					resolve({ xhrRequest, headers, status: xhrRequest.status });
 				}
 				}
 			};
 			};
 			xhrRequest.open("GET", url, true);
 			xhrRequest.open("GET", url, true);

+ 4 - 1
lib/single-file/single-file-browser.js

@@ -40,7 +40,10 @@ this.SingleFile = this.SingleFile || (() => {
 			} catch (error) {
 			} catch (error) {
 				return options && options.asDataURI ? "data:base64," : "";
 				return options && options.asDataURI ? "data:base64," : "";
 			}
 			}
-			let contentType = resourceContent.headers.get("content-type");
+			if (resourceContent.status >= 400) {
+				resourceContent = options && options.asDataURI ? "data:base64," : "";
+			}
+			let contentType = resourceContent.headers && resourceContent.headers.get("content-type");
 			if (contentType) {
 			if (contentType) {
 				contentType = contentType.match(/^([^;]*)/)[0];
 				contentType = contentType.match(/^([^;]*)/)[0];
 			}
 			}