Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add beforeError hook #417

Merged
merged 11 commits into from
Feb 15, 2022

Conversation

uchihamalolan
Copy link
Contributor

@uchihamalolan uchihamalolan commented Jan 11, 2022

Fixes #412

@sindresorhus
Copy link
Owner

Linting is not passing. Make sure you always run npm test locally before pushing commits.

@sindresorhus sindresorhus changed the title Adds beforeError Hook Add beforeError hook Jan 12, 2022
@sindresorhus
Copy link
Owner

It needs to be documented in the readme too.

@uchihamalolan
Copy link
Contributor Author

@sindresorhus I see this error which is not related to my changes:
Error: /Users/runner/work/ky/ky/test/helpers/with-page.ts: line 2, col 29, Error - 'ava/use-test' rule is disabled but never reported. (eslint-comments/no-unused-disable)

any idea what to be done about it?

@uchihamalolan
Copy link
Contributor Author

@sindresorhus Any update in this?


/**
Called with `HTTPError` instance. The error is passed to the hook right before it's thrown.
This is especially useful when you want to have more detailed errors.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Readme and TS docs should be in sync.

readme.md Outdated
Type: `Function[]`\
Default: `[]`

This hook enables you to modify the HTTPError right before it is thrown. The hook function receives `HTTPError` as argument and should return instance of HTTPError.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This hook enables you to modify the HTTPError right before it is thrown. The hook function receives `HTTPError` as argument and should return instance of HTTPError.
This hook enables you to modify the `HTTPError` right before it is thrown. The hook function receives `HTTPError` as argument and should return instance of `HTTPError`.

readme.md Outdated
await ky('https://example.com', {
hooks: {
beforeError: [
(error) => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(error) => {
error => {

@sindresorhus sindresorhus merged commit 616d276 into sindresorhus:main Feb 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

beforeError hook
2 participants