-
-
Notifications
You must be signed in to change notification settings - Fork 485
[SoundCloud] Validate HTTP response codes #1322
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
base: dev
Are you sure you want to change the base?
[SoundCloud] Validate HTTP response codes #1322
Conversation
Use @nested and TestInstance.Lifecycle.PER_CLASS to remove warnings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thaank you. Changes LGTM, but conflicts need to be resolved first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this can be merged in the current state:
- There are Todo comments
- The changes in the test will be irrelevant after #1332
- Response codes that are ok are 2XX response codes
- I'm really not sure about another HttpUtils method and a new Exception class
I think the most simple approach would be to have a boolean Response#isOk()
method and then use this method to control the underlying use cases accordingly.
The comment was kind of intentionally left in there in the hopes that whoever reviewed it would provide an explanation and then I would remove it.
Not exactly sure what you mean by this? Do you mean that 2xx is the only "success" code range all network calls throughout the codebase?
Do you mean another as in having two And does this also mean we shouldn't have a My idea was to have a generic method we can use to check for expected response codes instead of just checking it's 2xx or not 2xx, because I was of the assumption that:
The end goal is that if a network call ever fails, we want to know why, using code that is:
If there's only one place in code where non-2xx codes shouldn't be considered an error then we could handle that case explicitly at that call site, but if it's at least 3 times then I think we should have more than a simple Since I am almost certain 1. is true, I am more than happy to trawl through the entire codebase for every http call we make (not jusr for I could update this PR with these changes and/or split it into multiple PRs if it is too big. Thoughts? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! We do need to check response codes more often. For example, PeerTube sometimes throws 429 Too Many Requests (TeamNewPipe/NewPipe#2979), but that shouldn't be treated as a recaptcha by the Downloader
(while that's what happens now). It should be the PeerTube service's job to throw a normal ExtractorException for 429s, and instead the YouTube service's job to throw a RecaptchaException (along with a proper URL that users can use to solve the captcha, instead of having the Downloader
guess that URL).
It would be good if you could take the above paragraph into consideration for this PR, and properly validate the HTTP response codes of all requests made by all services in the extractor, so we don't have to change the design once again later.
* or when {@code validResponseCodes} is empty and the code is a 4xx or 5xx error. | ||
*/ | ||
// CHECKSTYLE:ON | ||
public static void validateResponseCode(final Response response, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would inline this directly in Response
, especially because it's first argument is a Response
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah changes in this file should be reverted as they were superseded
import java.io.IOException; | ||
import org.schabi.newpipe.extractor.downloader.Response; | ||
|
||
public class HttpResponseException extends IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be an ExtractorException
, since the extractor received an unexpected response. There was no error in data input/output, since the request went through just fine at the network layer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, problem with this. If this is changed to ExtractionException
, then that means any code that validates HttpResponseException will also now need to have throws ExtractionException
.
Is this something we want or not?
|
||
return null; | ||
} | ||
// CHECKSTYLE:OFF |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why checkstyle off?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC, checkstyle was complaining about line being too long in the comment below, so I had to disable it
Validate HTTP response codes for Soundcloud
Production code that was using Downloader does not do any checking on the response code: therefore errors and exceptions thrown due to error response code give false information (e.g. tests failing due to 404 were giving error about
clientId
when the error was 404).I added a method in Response.java and a utility method for validating response codes and used it in places for soundcloud extraction. It will throw exception with information about the error code, which will propagate upwards to the call site which will print a more useful stack trace for debugging.
Fix failing tests in SoundcloudChannelTabExtractorTest