Move to node fetch API for web requests instead of XHR (#1552)

* Use node-fetch instead of xhr

* Remove XMLHttpRequest.js

// FREEBIE

* Avoid calling json() on non json responses

Previously we would catch and swallow JSON parsing errors resulting from an
empty response, though empty responses are normal from a few endpoints, like
requesting sms or voice registration codes.

Since the JSON parsing call is now handled internally by node-fetch, we have to
keep closer track of our expected response type to avoid throwing an exception.

// FREEBIE
This commit is contained in:
Lilia
2017-10-20 15:52:02 -07:00
committed by Scott Nonnenberg
parent 0d3c70151d
commit af8b0164b5
7 changed files with 177 additions and 770 deletions

View File

@@ -42,7 +42,6 @@
require('./js/backup');
window.nodeSetImmediate = setImmediate;
window.nodeXMLHttpRequest = require("./js/XMLHttpRequest").XMLHttpRequest;
window.nodeWebSocket = require("websocket").w3cwebsocket;
// Linux seems to periodically let the event loop stop, so this is a global workaround
@@ -51,4 +50,7 @@
}, 1000);
window.EmojiConvertor = require('emoji-js');
window.nodeFetch = require('node-fetch');
window.httpsAgent = require('https').Agent;
window.nodeBuffer = Buffer;
})();