Skip to content

Commit

Permalink
Improve HTTP status code support
Browse files Browse the repository at this point in the history
Motivation:

The response should include the status code and reason phrase.

Modification:

Add generic handling of status code and reason phrase as extra args.
Update messages accordingly.

Add explicit support for 500 and 503 status codes.

Result:

More informative entries if the web-server returns an error status code.
  • Loading branch information
paulmillar committed Nov 2, 2022
1 parent 63f4b5b commit 6c610b9
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions bin/validate
Original file line number Diff line number Diff line change
Expand Up @@ -280,29 +280,45 @@ def check_result(future):
log_success="URL is good.")
elif not r.ok:
logging.debug("%s %d %s", r.url, r.status_code, r.reason)
extra_args={"status_code": str(r.status_code)}
if r.reason:
extra_args["reason_phrase"] = r.reason

if r.status_code == 401:
append_problem(problems, label, r.url,
"PERMISSION",
"The server requires authentication to allow access to the resource.")
"The server requires authentication to allow access to the resource.",
**extra_args)
if r.status_code == 403:
append_problem(problems, label, r.url,
"PERMISSION",
"The server understood the request, but is refusing to authorize it.")
"The server understood the request, but is refusing to authorize it.",
**extra_args)
elif r.status_code == 404:
append_problem(problems, label, r.url,
"MISSING",
"The server could not find this resource, which may be because of a temporary problem.")
"The server could not find this resource (might be a temporary problem).",
**extra_args)
elif r.status_code == 410:
append_problem(problems, label, r.url,
"MISSING",
"The server asserts this resource has been permanently removed.")
"The server asserts this resource has been permanently removed.",
**extra_args)
elif r.status_code == 500:
append_problem(problems, label, r.url,
"BAD SERVER",
"A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.",
**extra_args)
elif r.status_code == 503:
append_problem(problems, label, r.url,
"BAD SERVER",
"The server cannot handle the request (because it is overloaded or down for maintenance). Generally, this is a temporary state.",
**extra_args)
else:
# REVISIT: do we want more specific cases here?
append_problem(problems, label, r.url,
"HTTP",
"Web-server indicated a problem: %d %s"
% (r.status_code, r.reason))
"Web-server indicated a problem",
**extra_args)
else:
if not verify and try_alternative_fqdn:
# To get here, the URL required switching off
Expand Down

0 comments on commit 6c610b9

Please sign in to comment.