chore: modernize HandleResponseError to support errors.As#2646
Open
cstockton wants to merge 1 commit into
Open
chore: modernize HandleResponseError to support errors.As#2646cstockton wants to merge 1 commit into
cstockton wants to merge 1 commit into
Conversation
Replace the type switches in handleResponseError with errors.As
checks by dispatching to new functions for each error type:
* `HandleResponseError` creates log entry and apiVersion before
calling private func `handleResponseError` which accepts the
log and apiVersion. This heeps the recursion that happens in
`handleResponseErrorCause` cause case from executing twice
which can log two errors if invalid.
* `handleResponseError` contains a single switch statement that
dispatches to one of the following funcs in the same sequence
as previously.
* `handleResponseErrorWeakPassword`
* `handleResponseErrorHTTP`
* `handleResponseErrorOAuth`
* `handleResponseErrorCause`
* `handleResponseErrorDefault`
* Each private err handler contains the previous code block for
the type switch case and returns a bool to signal if the error
was handled or not.
This should not include any behavior change today, it only
enables wrapping errors without hiding them in responses.
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.
Replace the type switches in handleResponseError with errors.As checks by dispatching to new functions for each error type:
HandleResponseErrorcreates log entry and apiVersion before calling private funchandleResponseErrorwhich accepts the log and apiVersion. This keeps the recursion that happens inhandleResponseErrorCausecause case from executing twice which can log two errors if invalid.handleResponseErrorcontains a single switch statement that dispatches to one of the following funcs in the same sequence as previously.handleResponseErrorWeakPasswordhandleResponseErrorHTTPhandleResponseErrorOAuthhandleResponseErrorCausehandleResponseErrorDefault