Skip to content

Commit 997bd8f

Browse files
trevorahleebyron
authored andcommitted
fix elasticsearch errors being mistaken for graphql errors (#1090)
1 parent aea5964 commit 997bd8f

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import { expect } from 'chai';
9+
import { describe, it } from 'mocha';
10+
11+
import { GraphQLError } from '../../';
12+
import { locatedError } from '../locatedError';
13+
14+
describe('locatedError', () => {
15+
16+
it('passes GraphQLError through', () => {
17+
const e = new GraphQLError(
18+
'msg',
19+
null,
20+
null,
21+
null,
22+
[ 'path', 3, 'to', 'field' ]
23+
);
24+
25+
expect(locatedError(e, [], [])).to.deep.equal(e);
26+
});
27+
28+
it('passes GraphQLError-ish through', () => {
29+
const e = new Error('I have a different prototype chain');
30+
e.locations = [];
31+
e.path = [];
32+
e.nodes = [];
33+
e.source = null;
34+
e.positions = [];
35+
e.name = 'GraphQLError';
36+
37+
expect(locatedError(e, [], [])).to.deep.equal(e);
38+
});
39+
40+
it('does not pass through elasticsearch-like errors', () => {
41+
const e = new Error('I am from elasticsearch');
42+
e.path = '/something/feed/_search';
43+
44+
expect(locatedError(e, [], [])).to.not.deep.equal(e);
45+
});
46+
47+
});

src/error/locatedError.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function locatedError(
2222
): GraphQLError {
2323
// Note: this uses a brand-check to support GraphQL errors originating from
2424
// other contexts.
25-
if (originalError && originalError.path) {
25+
if (originalError && Array.isArray(originalError.path)) {
2626
return (originalError: any);
2727
}
2828

0 commit comments

Comments
 (0)