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

fix(basic-crawler): handle request.noRetry after errorHandler #1542

Merged
merged 5 commits into from
Sep 16, 2022

Conversation

mstephen19
Copy link
Contributor

@mstephen19 mstephen19 commented Sep 15, 2022

See this Discord post to fully understand the use case: https://discord.com/channels/801163717915574323/1019936393235017769

Didn't want to make big changes to existing code so kept the else statement and, therefore,the code repeats itself a little. If a refactor is in order, I can easily fix.

@szmarczak
Copy link
Contributor

Hmm... This should be already working

if (request.noRetry || (error instanceof NonRetryableError)) {

@mstephen19
Copy link
Contributor Author

mstephen19 commented Sep 16, 2022

The code within _canRequestBeRetried() is correct. But preventing a request from being retried conditionally is not working without my fix.

This is because shouldRetryRequest is determined BEFORE the user's provided errorHandler is run. Within their error handler, they might have a conditional statement saying that if the error contains the string "foo", the request should not be retried anymore and they would do request.noRetry = true. BUT we don't check if they did this. We must check if noRetry has been set to true in the errorHandler, and if so, must treat the request as if it is finished. Without this fix, the request will retried once, then the second time around wont be retried again.

If a reproducible example is needed to show what I'm talking about, I can provide one.

@szmarczak

@szmarczak szmarczak changed the title feat(basic-crawler): allow request skipping fix(basic-crawler): handle request.noRetry after errorHandler Sep 16, 2022
@szmarczak szmarczak merged commit 2a2040e into master Sep 16, 2022
@szmarczak szmarczak deleted the allow-request-short-circuit branch September 16, 2022 15:06
@metalwarrior665
Copy link
Member

@mstephen19 Just a note, I would probably not change the if/else flow to if/return. That is a refactoring that should be done separately and here it really messes up the diff (or it was messed by something else?).

@mstephen19
Copy link
Contributor Author

@metalwarrior665 you know me too well (me and my hatred for else) :P but yeah as I said up above, I only added a few lines of code and a comment. Didn't want to change things and left refactoring for Szymon or Banan to decide. Szymon did make some changes to the PR tho, which I trust.

@B4nan
Copy link
Member

B4nan commented Sep 16, 2022

else is antipattern, early return ftw :] we need to add eslint rule for this (no-else-return)

Copy link

@Avaronea Avaronea left a comment

Choose a reason for hiding this comment

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

Review

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.

None yet

5 participants