Skip to content

Commit

Permalink
fix: subclass Error by explicitly setting prototype (#101)
Browse files Browse the repository at this point in the history
Co-authored-by: Jason Kuhrt <jason.kuhrt@dialogue.co>
  • Loading branch information
ughitsaaron and Jason Kuhrt committed May 28, 2020
1 parent c22d4b0 commit 5cb1aa1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/types.ts
Expand Up @@ -31,6 +31,8 @@ export class ClientError extends Error {

super(message)

Object.setPrototypeOf(this, ClientError.prototype)

this.response = response
this.request = request

Expand Down
7 changes: 3 additions & 4 deletions tests/index.test.ts
Expand Up @@ -77,10 +77,8 @@ test('basic error', async (t) => {
],
}

await mock({ body: { errors } }, async () => {
const err: ClientError = await t.throws(
request('https://mock-api.com/graphql', `x`),
)
await mock({body: {errors}}, async () => {
const err: ClientError = await t.throws(request('https://mock-api.com/graphql', `x`), ClientError)
t.deepEqual<any>(err.response.errors, errors)
})
})
Expand All @@ -100,6 +98,7 @@ test('raw request error', async (t) => {
await mock({ body: { errors } }, async () => {
const err: ClientError = await t.throws(
rawRequest('https://mock-api.com/graphql', `x`),
ClientError
)
t.deepEqual<any>(err.response.errors, errors)
})
Expand Down

0 comments on commit 5cb1aa1

Please sign in to comment.