diff --git a/app.fetch.js b/app.fetch.js index 25fa383..d4f8703 100644 --- a/app.fetch.js +++ b/app.fetch.js @@ -1049,7 +1049,15 @@ class SocketFetch extends ArcEventSource { try { this._processSocketMessage(readInfo.data); } catch (e) { - console.error('Fix me please', e); + if (this.state === SocketFetch.STATUS || + this.state === SocketFetch.HEADERS) { + // The response is totally wrong! + this._errorRequest({ + 'message': e.message || 'Unknown error occurred' + }); + return; + } + console.error('Error occured reading part of the message', e); } chrome.sockets.tcp.setPaused(this._connection.socketId, false); } @@ -1519,6 +1527,7 @@ class SocketFetch extends ArcEventSource { // Finishes the response with error message. _errorRequest(opts) { this.aborted = true; + this.state = SocketFetch.DONE; var message; if (opts.code && !opts.message) { message = this.getCodeMessage(opts.code); diff --git a/demo/index.html b/demo/index.html index 247df4a..e910c7d 100644 --- a/demo/index.html +++ b/demo/index.html @@ -123,8 +123,8 @@

Log

demo.url = ''; demo.payload = ''; demo.headers = ''; - demo.method = 'POST'; - + // demo.method = 'POST'; + demo.method = 'GET'; demo.addEventListener('dom-change', function() { // demo.url = 'https://chromerestclient.appspot.com/test?p=json'; // demo.url = 'http://localhost:8081/redirect'; @@ -133,8 +133,8 @@

Log

demo.url = 'http://localhost:8081/post-redirect'; // demo.url = 'http://192.168.1.25/'; demo.url = 'http://localhost:8081/ntlm'; - demo.set('payload', '{"test":"request"}'); - demo.set('method', 'POST'); + // demo.set('payload', '{"test":"request"}'); + // demo.set('method', 'POST'); demo.set('headers', `Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 Accept-Encoding: gzip, deflate @@ -149,12 +149,12 @@

Log

'headers': new Headers(headersToObject(demo.headers)), 'debug': true, 'timeout': 5000, - 'auth': { - 'uid': 'test', - 'passwd': 'test', - 'domain': 'workgroup', - 'method': 'ntlm' - } + // 'auth': { + // 'uid': 'test', + // 'passwd': 'test', + // 'domain': 'workgroup', + // 'method': 'ntlm' + // } }; if (demo.method === 'POST') { init.body = demo.payload;