From 9fc275ed18e1d74dabb14fadf1e627b657981bb9 Mon Sep 17 00:00:00 2001 From: Sashko Stubailo Date: Tue, 10 May 2016 23:20:56 -0700 Subject: [PATCH 1/5] Print unhandled network errors to console --- src/QueryManager.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/QueryManager.ts b/src/QueryManager.ts index ecb4d4c7d13..0478672978b 100644 --- a/src/QueryManager.ts +++ b/src/QueryManager.ts @@ -188,6 +188,8 @@ export class QueryManager { // XXX we might not want to re-broadcast the same error over and over if it didn't change if (observer.error) { observer.error(queryStoreValue.networkError); + } else { + console.error('Unhandled network error', queryStoreValue.networkError); } } else { const resultFromStore = readSelectionSetFromStore({ From be5c958193788a45fe84c856a1b4342a713a6bb2 Mon Sep 17 00:00:00 2001 From: Sashko Stubailo Date: Tue, 10 May 2016 23:28:49 -0700 Subject: [PATCH 2/5] Write test --- test/QueryManager.ts | 47 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/test/QueryManager.ts b/test/QueryManager.ts index 2c80a4d3d92..b1fc3240ea6 100644 --- a/test/QueryManager.ts +++ b/test/QueryManager.ts @@ -354,6 +354,53 @@ describe('QueryManager', () => { }); }); + it('uses console.error to log unhandled errors', (done) => { + const query = gql` + query people { + allPeople(first: 1) { + people { + name + } + } + } + `; + + const networkInterface = mockNetworkInterface( + { + request: { query }, + error: new Error('Network error'), + } + ); + + const queryManager = new QueryManager({ + networkInterface, + store: createApolloStore(), + reduxRootKey: 'apollo', + }); + + const handle = queryManager.watchQuery({ + query, + }); + + const oldError = console.error; + let printed; + console.error = (...args) => { + printed = args; + } + + handle.subscribe({ + next: (result) => { + done(new Error('Should not deliver result')); + } + }); + + setTimeout(() => { + assert.match(printed[0], /error/); + console.error = oldError; + done(); + }); + }); + it('handles an unsubscribe action that happens before data returns', (done) => { const query = gql` query people { From eb2fc7212b9dc694603826dab4dfef999bb6b6bf Mon Sep 17 00:00:00 2001 From: Sashko Stubailo Date: Tue, 10 May 2016 23:30:20 -0700 Subject: [PATCH 3/5] Add to change log --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85dbafd6de8..e375d08e7a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Expect active development and potentially significant breaking changes in the `0 ### vNEXT +- Use `console.error` to log unhandled network errors. [Issue #189](https://github.com/apollostack/apollo-client/issues/189) [PR #203](https://github.com/apollostack/apollo-client/pull/203) - ... ### v0.3.5 From da7e53f86fcef6feb3e48bca69aee3f5ce40fd39 Mon Sep 17 00:00:00 2001 From: Sashko Stubailo Date: Tue, 10 May 2016 23:39:48 -0700 Subject: [PATCH 4/5] Fix hidden test weirdness --- src/QueryManager.ts | 4 +++- test/QueryManager.ts | 5 ++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/QueryManager.ts b/src/QueryManager.ts index 0478672978b..8a86cd3d00f 100644 --- a/src/QueryManager.ts +++ b/src/QueryManager.ts @@ -189,7 +189,9 @@ export class QueryManager { if (observer.error) { observer.error(queryStoreValue.networkError); } else { - console.error('Unhandled network error', queryStoreValue.networkError); + console.error('Unhandled network error', + queryStoreValue.networkError, + queryStoreValue.networkError.stack); } } else { const resultFromStore = readSelectionSetFromStore({ diff --git a/test/QueryManager.ts b/test/QueryManager.ts index b1fc3240ea6..72de7b3503f 100644 --- a/test/QueryManager.ts +++ b/test/QueryManager.ts @@ -398,7 +398,7 @@ describe('QueryManager', () => { assert.match(printed[0], /error/); console.error = oldError; done(); - }); + }, 10); }); it('handles an unsubscribe action that happens before data returns', (done) => { @@ -1510,7 +1510,6 @@ describe('QueryManager', () => { request: { query, variables }, result: { data: data2 }, } - ); const queryManager = new QueryManager({ @@ -1534,13 +1533,13 @@ describe('QueryManager', () => { assert.deepEqual(result.data, data1); } else if (handleCount === 2) { assert.deepEqual(result.data, data2); + subscription.unsubscribe(); done(); } }, }); subscription.startPolling(50); - }); it('exposes a way to stop a polling query', (done) => { const query = gql` From 55c4288ab340fba747aa60f3d33f064830031fdd Mon Sep 17 00:00:00 2001 From: Sashko Stubailo Date: Tue, 10 May 2016 23:40:52 -0700 Subject: [PATCH 5/5] Fix lint errors --- test/QueryManager.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/QueryManager.ts b/test/QueryManager.ts index 72de7b3503f..8f922a1e908 100644 --- a/test/QueryManager.ts +++ b/test/QueryManager.ts @@ -386,12 +386,12 @@ describe('QueryManager', () => { let printed; console.error = (...args) => { printed = args; - } + }; handle.subscribe({ next: (result) => { done(new Error('Should not deliver result')); - } + }, }); setTimeout(() => {