From 7e9c3f77cce881dbb47af266993da5a2b6e98b5b Mon Sep 17 00:00:00 2001 From: anthony Date: Wed, 26 Sep 2018 13:42:50 -0700 Subject: [PATCH] Fix HEAD request failing with `Invalid response for blob` (#19567) Summary: Fixes #18223 This is a fairly simple solution to what seems to be a recurring issue where certain requests that result in an empty body where JSON is expected throw an error rather than being handled gracefully. Client side error handling is not being hit as this is being thrown at a lower level. Make a http request that results in an empty blob: "" [INTERNAL] [BUGFIX] [XMLHttpRequest.js] - Line 262 Pull Request resolved: https://github.com/facebook/react-native/pull/19567 Differential Revision: D8314416 Pulled By: hramos fbshipit-source-id: a17c49f3620f0abbb936f3a1c2b01aa1b64820fd --- Libraries/Network/XMLHttpRequest.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Libraries/Network/XMLHttpRequest.js b/Libraries/Network/XMLHttpRequest.js index fd6e756e38c087..98d8bedd401288 100644 --- a/Libraries/Network/XMLHttpRequest.js +++ b/Libraries/Network/XMLHttpRequest.js @@ -246,7 +246,9 @@ class XMLHttpRequest extends EventTarget(...XHR_EVENTS) { case 'blob': if (typeof this._response === 'object' && this._response) { this._cachedResponse = BlobManager.createFromOptions(this._response); - } else { + } else if (this._response === '') { + this._cachedResponse = null; + } else { throw new Error(`Invalid response for blob: ${this._response}`); } break;