mirror of
https://github.com/vale981/apollo-server
synced 2025-03-06 02:01:40 -05:00
apollo-server-core: capture context creation failure in GraphQL error
This commit is contained in:
parent
5aeb36f3d7
commit
0fe53a68da
1 changed files with 19 additions and 1 deletions
|
@ -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)),
|
||||
|
|
Loading…
Add table
Reference in a new issue