Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

formatError error ignores custom error properties #421

Closed
teckays opened this issue Feb 21, 2018 · 4 comments
Closed

formatError error ignores custom error properties #421

teckays opened this issue Feb 21, 2018 · 4 comments

Comments

@teckays
Copy link

teckays commented Feb 21, 2018

I am throwing a custom error inside the resolver with additional parameters, unfortunately all custom fields are being stripped out from the formatError: error => {} callback.

// error 
class CustomError {
    constructor () {
        this.foo = 'bar'
    }
}

// resolver
try {
     throw new CustomError()
}

// graphQL
...
formatError: err => {
    console.log(err.foo) // undefined
}
@teckays
Copy link
Author

teckays commented Feb 21, 2018

Sorry, figured out that this is actually a bug in the graphql-js package

@teckays
Copy link
Author

teckays commented Feb 21, 2018

A "not very obvious err.originalError solution" found here: graphql/graphql-js#1192

@teckays teckays closed this as completed Feb 21, 2018
@IvanGoncharov
Copy link
Member

@teckays You don't need to replace formatError at all. If you do:

class CustomError {
    constructor () {
        this.extensions = { foo: 'bar' };
    }
}

It will be automatically exposed 🎉

@vnphanquang
Copy link

@teckays You don't need to replace formatError at all. If you do:

class CustomError {
    constructor () {
        this.extensions = { foo: 'bar' };
    }
}

It will be automatically exposed 🎉

I think this piece of information would be very helpful if added to the documentation (README). formatError is also helpful.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants