Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make single error instance of Error to prevent [object Object] error messages #1048

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/stitching/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export function checkResultAndHandleErrors(
// If there is only one error, which contains a result property, pass the error through
const newError =
result.errors.length === 1 && hasResult(result.errors[0])
? result.errors[0]
? Object.setPrototypeOf(result.errors[0], Error.prototype)
: new CombinedError(concatErrors(result.errors), result.errors);
throw locatedError(newError, info.fieldNodes, responsePathAsArray(info.path));
}
Expand Down
18 changes: 18 additions & 0 deletions src/test/testErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,23 @@ describe('Errors', () => {
});
}
});

it('persists single error that is instance of Error if the initial error has path and extensions and is instance of Object', () => {
const result = {
errors: [
{
message: 'Test error',
extensions: {},
path: [] as any,
} as GraphQLError
]
};
try {
checkResultAndHandleErrors(result, {} as GraphQLResolveInfo, 'responseKey');
} catch (e) {
assert.equal(e.message, 'Test error');
assert.instanceOf(e, Error);
}
});
});
});