This repository was archived by the owner on Mar 20, 2023. It is now read-only.
This repository was archived by the owner on Mar 20, 2023. It is now read-only.
Custom error obejct properties are not propagated to originalError
from a rejected promise #536
Closed
Description
In graphql/graphql-js#251, we added originalError
to be able to look at the original error object and read stuff from it.
Great! Inside of formatError
, I want to be able to see a custom property on the original error object.
works (regular synchronous Error
):
const resolvers = {
foo: () => {
try {
throw new Error('yikes!');
} catch (e) {
e.foo = "bar";
throw e;
}
}
};
formatError: e => {
console.log("originalError", e.originalError.foo); // logs 'bar'
return e;
}
does not work (async Promise.reject
):
const resolvers = {
foo: async () => {
try {
await Promise.reject("yikes!");
} catch (e) {
e.foo = "bar";
throw e;
}
}
};
formatError: e => {
console.log("originalError", e.originalError.foo); // logs 'undefined'
return e;
}
Repro: https://codesandbox.io/embed/nodejs-graphql-server-xo0vh
Not sure if this is intended, or if this is to do with there being some difference between an error object and a rejected promise, but we seem to treat rejected promises and synchronous errors the same elsewhere 🤔
Thoughts?
Thanks!!
Metadata
Metadata
Assignees
Labels
No labels