Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log unhandled network errors #203

Merged
merged 5 commits into from
May 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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