Skip to content

chore: modernize HandleResponseError to support errors.As#2646

Open
cstockton wants to merge 1 commit into
masterfrom
cs/modernize-error-handling
Open

chore: modernize HandleResponseError to support errors.As#2646
cstockton wants to merge 1 commit into
masterfrom
cs/modernize-error-handling

Conversation

@cstockton

Copy link
Copy Markdown
Contributor

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 keeps 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.

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.
@cstockton
cstockton requested a review from a team as a code owner July 24, 2026 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant