Skip to content

Commit

Permalink
apollo-server-core: capture context creation failure in GraphQL error
Browse files Browse the repository at this point in the history
  • Loading branch information
evans committed May 3, 2018
1 parent dfccfa6 commit 2a36f0f
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion packages/apollo-server-core/src/runHttpQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,25 @@ export async function runHttpQuery(
//appease typescript compiler, otherwise could use || {}
context = {};
} else if (typeof context === 'function') {
context = await context();
try {
context = await context();
} catch (e) {
e.message = `Context creation failed: ${e.message}`;
throw new HttpQueryError(
500,
JSON.stringify({
errors: formatApolloErrors([e], {
formatter: optionsObject.formatError,
debug,
logFunction: optionsObject.logFunction,
}),
}),
true,
{
'Content-Type': 'application/json',
},
);
}
} else if (isBatch) {
context = Object.assign(
Object.create(Object.getPrototypeOf(context)),
Expand Down

0 comments on commit 2a36f0f

Please sign in to comment.