Skip to content
This repository was archived by the owner on Sep 10, 2019. It is now read-only.
This repository was archived by the owner on Sep 10, 2019. It is now read-only.

Errors do not bubble up to formatError #6

@timrs2998

Description

@timrs2998

Summary

I'm creating an issue here so you're aware, but I ultimately believe this is an issue with graphql-tools. When throwing a GrampsError, graphql-tools removes all properties except error.message and rethrows a new error. As a result, the formatError provided by the @gramps/errors package is useless.

Walkthrough

When a GrampsError is thrown, it is caught by graphql-tools stitching logic and rethrown:

https://github.com/apollographql/graphql-tools/blob/master/src/stitching/errors.ts#L84

    const errorMessage = result.errors
      .map((error: { message: string }) => error.message)
      .join('\n');
    throw locatedError(
      new Error(errorMessage),
      ..,
      ..,
    );

Later, the new error bubbles up to the formatError logic from @gramps/errors:

import { formatError } from '@gramps/errors'

app.use(graphqlExpress({ formatError })

However, the formatError function does not receive the expected GrampsErrors, rather, it receives a different error object transformed and rethrown by graphql-tools. It cannot log the targetEndpoint, statusCode, docsLink, and other fields on a GrampsError because the error has been caught and rethrown by graphql-tools.

I can write a short gist to reproduce it if you want.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions