Skip to content

Commit

Permalink
Merge pull request #203 from apollostack/unhandled-network-error
Browse files Browse the repository at this point in the history
Log unhandled network errors
  • Loading branch information
Sashko Stubailo committed May 11, 2016
2 parents c890c43 + 55c4288 commit 94ee523
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/QueryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ 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,
queryStoreValue.networkError.stack);
}
} else {
const resultFromStore = readSelectionSetFromStore({
Expand Down
50 changes: 48 additions & 2 deletions test/QueryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}, 10);
});

it('handles an unsubscribe action that happens before data returns', (done) => {
const query = gql`
query people {
Expand Down Expand Up @@ -1463,7 +1510,6 @@ describe('QueryManager', () => {
request: { query, variables },
result: { data: data2 },
}

);

const queryManager = new QueryManager({
Expand All @@ -1487,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`
Expand Down

0 comments on commit 94ee523

Please sign in to comment.