Skip to content

Commit

Permalink
Expose TimeoutError#request (#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
ulken committed Nov 14, 2020
1 parent cfb7583 commit 599a45b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ The error thrown when the request times out.
*/
declare class TimeoutError extends Error {
constructor(request: Request);
request: Request;
}

declare const ky: {
Expand Down
2 changes: 2 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ try {
expectType<number>(status);
} else if (error instanceof ky.TimeoutError) {
expectType<ky.TimeoutError>(error);
const {method} = error.request;
expectType<string>(method);
} else {
throw error;
}
Expand Down
10 changes: 8 additions & 2 deletions test/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,15 @@ test('throws TimeoutError even though it does not support AbortController', with

const error = await page.evaluate(url => {
const request = window.ky(`${url}/slow`, {timeout: 500}).text();
return request.catch(error_ => error_.toString());
return request.catch(error_ => {
return {
message: error_.toString(),
request: {url: error_.request.url}
};
});
}, server.url);
t.is(error, 'TimeoutError: Request timed out');
t.is(error.message, 'TimeoutError: Request timed out');
t.is(error.request.url, `${server.url}/slow`);

await server.close();
});
Expand Down

0 comments on commit 599a45b

Please sign in to comment.