Repository navigation
Handle HTTP errors in check_url in one place - #1213
Open
minutechreview wants to merge 1 commit into
Open
minutechreview wants to merge 1 commit into
minutechreview wants to merge 1 commit into
Conversation
Signed-off-by: minutechreview <141821420+minutechreview@users.noreply.github.com>
minutechreview
requested review from
ahmdkaml,
propcgamer20-png and
yakew7
as code owners
October 27, 2026 10:16
Contributor
|
@minutechreview is attempting to deploy a commit to the yashkewlani2020-gmailcom's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@yakew7 @ahmdkaml @propcgamer20-png - new PR touching a path you own, please review. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
check_urlnow handles an HTTP error status in one place, so the 404 browser retry, the 403 DOI fallback and the 405/501 HEAD fallback are no longer written out twice.Type
Details
_open(url, method, user_agent, timeout)makes one request and returns("ok", status)._classify_http_error(error, url, method, timeout)turns anHTTPErrorintobroken, the DOI check result orunknown. It returnsNonewhen a HEAD request got 405 or 501, andcheck_urlthen tries GET._classify_network_error(error)handlesURLError(name does not resolve isbroken) andTimeoutError/OSError.check_url, a 404 on the first request is retried once with the browser user agent (GET if the first was HEAD). An error from the first request or from the retry then goes through the same classifier, so a rule only has to change once.No test files changed. To check the behaviour is the same, I ran the old and the new
check_urlagainst a local server with 15 status combinations (404 then 200 for a browser, 404 then 403 or 405 or 500 for a browser, HEAD-only 405/501, 403 on a DOI URL, and so on) plus a refused connection. Both versions returned the same(class, detail)for every case.Checks:
tests/test_check_external_links.py20 passed,ruff check faircode scripts testsandcheck_em_dash.pypass. One test,test_a_name_that_does_not_resolve_is_broken_and_a_refused_connection_is_unknown, fails on my machine both onmainand on this branch because my DNS resolver answers for.invalidnames. It is not related to this change.Linked issue
Closes #1194