Skip to content

feature: Add shouldRetry option - #75

Merged
sindresorhus merged 10 commits into
sindresorhus:mainfrom
pukuba:feature/should-retry
Dec 20, 2023
Merged

sindresorhus merged 10 commits into
sindresorhus:mainfrom
pukuba:feature/should-retry

Conversation

@pukuba

@pukuba pukuba commented Sep 28, 2023 •

Copy link
Copy Markdown
Contributor

Referencing #67 and #70, I've added the shouldRetry option.

Please review when you have time.

Fixes #70

@pukuba

pukuba commented Sep 29, 2023 •

Copy link
Copy Markdown
Contributor Author

I've checked the comments on the issue. Here are my thoughts.

In pRetry, using the shouldRetry method is beneficial for reducing the complexity of retry logic, enhancing code readability, and promoting reusability.

  • Reducing Complexity: The shouldRetry method allows for detailed error handling, enabling specific conditions for retrying. This separation of concerns simplifies the overall structure of the code.
  • Enhancing Code Readability: With shouldRetry, the retry logic is clear and concise, making the code easier to read and understand. It allows developers to easily discern under what conditions a retry will be attempted.
  • Promoting Reusability: The shouldRetry method can be reused across different parts of the application, ensuring consistency and reducing the need for redundant code.

Certainly, using bail is a good method, but I also think adding a shouldRetry option to p-retry is a good approach.

Respecting the code owner's opinion. If you have any additional thoughts, please leave a comment! @sindresorhus

@sindresorhus

Copy link
Copy Markdown
Owner

Not sure I trust this pull request. Your comment is clearly ChatGPT, so I'm going to assume the code changes are too.

@pukuba

pukuba commented Oct 17, 2023

Copy link
Copy Markdown
Contributor Author

I didn't use GPT to write code, but I used it to write PR because I'm not good at English.
The comment I wrote before contains my thoughts.

If you want to close, you can close. Feel free to give me your opinion.

Comment thread index.js Resolved
Comment thread index.d.ts Resolved
Comment thread index.d.ts Resolved
@pukuba
pukuba requested a review from sindresorhus October 25, 2023 16:14
Comment thread index.js Resolved
Comment thread test.js Resolved
@sindresorhus

Copy link
Copy Markdown
Owner

You need to add it to the readme too.

@pukuba
pukuba requested a review from sindresorhus November 7, 2023 14:51
Comment thread index.d.ts Resolved
@pukuba
pukuba requested a review from sindresorhus December 18, 2023 16:48
Comment thread readme.md Outdated

Decide if a retry should occur based on the error. Returning true triggers a retry, false aborts with the error.

shouldRetry is not called for TypeErrors (except network errors) and AbortError.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Suggested change
shouldRetry is not called for TypeErrors (except network errors) and AbortError.
It is not called for `TypeError` (except network errors) and `AbortError`.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

index.d.ts too

@pukuba
pukuba requested a review from sindresorhus December 20, 2023 14:08
@sindresorhus
sindresorhus merged commit b993a96 into sindresorhus:main Dec 20, 2023
@madmed88

Copy link
Copy Markdown

is it possible to backport this to v4?

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.

Ability to customize whether an error should be retried

3 participants