Skip to content

Commit

Permalink
apollo-engine-reporting: log 5xx response body
Browse files Browse the repository at this point in the history
We do craft these messages to be useful, so we want them in your logs!

This regressed in #1274.
  • Loading branch information
glasser committed Aug 27, 2019
1 parent c798068 commit 781108d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion packages/apollo-engine-reporting/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,11 @@ export class EngineReportingAgent<TContext = any> {
});

if (curResponse.status >= 500 && curResponse.status < 600) {
throw new Error(`${curResponse.status}: ${curResponse.statusText}`);
throw new Error(
`${curResponse.status}: ${
curResponse.statusText
} (${await curResponse.text()})`,
);
} else {
return curResponse;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1953,7 +1953,7 @@ export function testApolloServer<AS extends ApolloServerBase>(
const fakeEngineServer = http.createServer(async (_, res) => {
await return502Promise;
res.writeHead(502);
res.end();
res.end('Important text in the body');
});
await new Promise(resolve => {
fakeEngineServer.listen(0, '127.0.0.1', () => {
Expand Down Expand Up @@ -2006,6 +2006,7 @@ export function testApolloServer<AS extends ApolloServerBase>(
// Make sure we can get the 502 error from reporting.
const sendingError = await reportErrorPromise;
expect(sendingError.message).toContain('Error: 502: Bad Gateway');
expect(sendingError.message).toContain('Important text in the body');
} finally {
await new Promise(resolve => fakeEngineServer.close(() => resolve()));
}
Expand Down

0 comments on commit 781108d

Please sign in to comment.