3

I'm using apollo server and graphql and it's necessary to set a timeout so I use this with express:

   const server = app.listen({ port: 4000 }, () =>
       console.log( `The server is running in http://localhost:4000${server.graphqlPath}`));

   server.setTimeout(60000);

This works to set a timeout, but I receive the following message in my Apollo Server Playground:

{
  "error": "Failed to fetch. Please check your connection"
}

But I think is not ok to send only that text, so can I edit that message or add some properties to the error that I receive?, It take me a while to search in some places with no success.

Lin Du
  • 88,126
  • 95
  • 281
  • 483
andresloal
  • 65
  • 1
  • 5

1 Answers1

1

This error message is not sent by server-side. It's a client-side error.

Here is the source code of this error for graphql playground.

export function formatError(error, fetchingSchema: boolean = false) {
  const message = extractMessage(error)
  if (message === 'Failed to fetch') {
    const schemaMessage = fetchingSchema ? ' schema' : ''
    return { error: `${message}${schemaMessage}. Please check your connection` }
  }

  try {
    const ee = JSON.parse(message)
    return ee
  } catch (e) {
    //
  }

  return { error: message }
}
Lin Du
  • 88,126
  • 95
  • 281
  • 483