From e0332bb164a52dc70ac8ee844c5c61c353aeefa9 Mon Sep 17 00:00:00 2001 From: Evans Hauser Date: Wed, 2 May 2018 23:28:24 -0700 Subject: [PATCH] apollo-server-core: added formatApolloError arguments to subscription callback --- packages/apollo-server-core/src/ApolloServer.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/apollo-server-core/src/ApolloServer.ts b/packages/apollo-server-core/src/ApolloServer.ts index af2c7eb8..db2d850b 100644 --- a/packages/apollo-server-core/src/ApolloServer.ts +++ b/packages/apollo-server-core/src/ApolloServer.ts @@ -19,7 +19,7 @@ import { import { formatApolloErrors } from './errors'; import { GraphQLServerOptions as GraphQLOptions } from './graphqlOptions'; -import { LogFunction } from './logging'; +import { LogFunction, LogAction, LogStep } from './logging'; import { Config, @@ -212,7 +212,13 @@ export class ApolloServerBase { onOperation: async (_: string, connection: ExecutionParams) => { connection.formatResponse = (value: ExecutionResult) => ({ ...value, - errors: value.errors && formatApolloErrors(value.errors), + errors: + value.errors && + formatApolloErrors(value.errors, { + formatter: this.requestOptions.formatError, + debug: this.requestOptions.debug, + logFunction: this.requestOptions.logFunction, + }), }); let context: Context = this.context ? this.context : { connection }; @@ -222,8 +228,11 @@ export class ApolloServerBase { ? await this.context({ connection }) : context; } catch (e) { - console.error(e); - throw e; + throw formatApolloErrors([e], { + formatter: this.requestOptions.formatError, + debug: this.requestOptions.debug, + logFunction: this.requestOptions.logFunction, + })[0]; } return { ...connection, context };