-
-
Notifications
You must be signed in to change notification settings - Fork 820
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Maintain original errors where possible (#637)
* Maintain original errors where possible * Updated changelog to include details of this change * removed .only on new testErrors.ts
- Loading branch information
1 parent
8a9585d
commit 69228d0
Showing
4 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { assert } from 'chai'; | ||
import { | ||
GraphQLResolveInfo | ||
} from 'graphql'; | ||
import { | ||
checkResultAndHandleErrors | ||
} from '../stitching/errors'; | ||
|
||
import 'mocha'; | ||
|
||
|
||
class ErrorWithResult extends Error { | ||
public result: any; | ||
constructor(message: string, result: any) { | ||
super(message); | ||
this.result = result; | ||
} | ||
} | ||
|
||
describe('Errors', () => { | ||
describe('checkResultAndHandleErrors', () => { | ||
it('persists single error with a result', done => { | ||
const result = { | ||
errors: [new ErrorWithResult('Test error', 'result')] | ||
}; | ||
try { | ||
checkResultAndHandleErrors(result, {} as GraphQLResolveInfo, 'responseKey'); | ||
} catch (e) { | ||
assert.equal(e.message, 'Test error'); | ||
assert.isUndefined(e.originalError.errors); | ||
done(); | ||
} | ||
}); | ||
|
||
it('persists original errors without a result', done => { | ||
const result = { | ||
errors: [new Error('Test error')] | ||
}; | ||
try { | ||
checkResultAndHandleErrors(result, {} as GraphQLResolveInfo, 'responseKey'); | ||
} catch (e) { | ||
assert.equal(e.message, 'Test error'); | ||
assert.isNotEmpty(e.originalError); | ||
assert.isNotEmpty(e.originalError.errors); | ||
assert.lengthOf(e.originalError.errors, result.errors.length); | ||
result.errors.forEach((error, i) => { | ||
assert.deepEqual(e.originalError.errors[i], error); | ||
}); | ||
|
||
done(); | ||
} | ||
}); | ||
|
||
it('combines errors and perists the original errors', done => { | ||
const result = { | ||
errors: [ | ||
new Error('Error1'), | ||
new Error('Error2') | ||
] | ||
}; | ||
try { | ||
checkResultAndHandleErrors(result, {} as GraphQLResolveInfo, 'responseKey'); | ||
} catch (e) { | ||
assert.equal(e.message, 'Error1\nError2'); | ||
assert.isNotEmpty(e.originalError); | ||
assert.isNotEmpty(e.originalError.errors); | ||
assert.lengthOf(e.originalError.errors, result.errors.length); | ||
result.errors.forEach((error, i) => { | ||
assert.deepEqual(e.originalError.errors[i], error); | ||
}); | ||
|
||
done(); | ||
} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters