diff --git a/src/types.ts b/src/types.ts index 9ab9e3dae..e4f1987dc 100644 --- a/src/types.ts +++ b/src/types.ts @@ -31,6 +31,8 @@ export class ClientError extends Error { super(message) + Object.setPrototypeOf(this, ClientError.prototype) + this.response = response this.request = request diff --git a/tests/index.test.ts b/tests/index.test.ts index a3194f8d2..5cf04acc9 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -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(err.response.errors, errors) }) }) @@ -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(err.response.errors, errors) })