Add request context to HTTPClientError.unexpectedStatusCode and CustomStringConvertible conformance#175
Open
krishnapermi wants to merge 2 commits into
Open
Conversation
…le conformance Adds the originating HTTPRequest to the unexpectedStatusCode error case so callers can surface the registry hostname in diagnostics. Also adds CustomStringConvertible to produce user-friendly messages like "Authentication failed for registry \"ghcr.io\": the server returned HTTP 401."
…dition The unexpectedStatusCode enum case now carries a leading request parameter. Update the two catch patterns in RegistryClient to bind a wildcard for it so the code continues to compile.
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.
Closes #118
What
Two related changes to
HTTPClientError:Adds the originating
HTTPRequestto theunexpectedStatusCodecase. The other two error cases that involve a remote server (unauthorized,authenticationChallenge) already carry the request so callers can surface the registry hostname in diagnostics.unexpectedStatusCodewas the odd one out.Adds
CustomStringConvertibleconformance. The implementation uses the newrequestfield to produce user-readable messages that include the registry hostname and a tailored explanation for 401/403 responses, for example:I noticed the inconsistency while reading through the error type —
unauthorizedandauthenticationChallengeboth thread the request through so their error messages can mention the host, butunexpectedStatusCodedropped it on the floor. This meant the most common error case (any non-2xx response) produced the least informative message.Changes
Sources/ContainerRegistry/HTTPClient.swift: addsrequest: HTTPRequestas the first label onunexpectedStatusCode, threads the request through both throw sites invalidateAPIResponseThrowing, and adds theCustomStringConvertibleextension.Sources/ContainerRegistry/RegistryClient.swift: updates the twocatchclauses that pattern-match onunexpectedStatusCodeto bind a wildcard for the new leadingrequestparameter.