graphqlapolloapollo-serverjson-server

Handling error in apollo graphql returns invalid doctype even when content type is json


I have tried sending 404 status using json-server and it works with postman as seen below.

enter image description here

But when I'm doing it inside apollo sandbox, it's giving me this invalid doctype. Not sure why json-server is sending out html instead of json content type because I've already set it

enter image description here

Here is the json-server enter image description here

Here's my datasource enter image description here

I tried casting the error to ApolloError but to no avail

throw new ApolloError('InputValidationError', 'INVALID_INPUT', { error });

The server enter image description here

What am I missing?


Solution

  • Forgot to add error formatting in the server. Refer to https://www.apollographql.com/docs/apollo-server/v2/data/errors/#masking-and-logging-errors

    formatError: (err) => { return err; },