Handle HTTP status codes in the HTTP breaker example - #121
Open
ZayanKhan-12 wants to merge 1 commit into
Open
ZayanKhan-12 wants to merge 1 commit into
ZayanKhan-12 wants to merge 1 commit into
Conversation
The example treated any completed request as a success, so a server returning 500s never tripped the circuit breaker, and error pages such as 404 were returned to the caller as the response body with no indication that anything went wrong. Return a StatusError for non-2xx responses so callers get the status context, and use Settings.IsSuccessful so that only transport errors and 5xx responses count as circuit breaker failures; client errors such as 404 are handled responses and do not trip the breaker. Fixes sony#46 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Fixes #46
The
example/http_breaker.goexample (and its v2 counterpart) treated any completed request as a success:This PR updates both examples to:
StatusErrorfor non-2xx responses, so callers always get operational context instead of error-page HTML;Settings.IsSuccessfulso that only transport errors and 5xx responses count as circuit breaker failures.The
IsSuccessfulsplit follows the discussion in #46: client errors such as 404 are responses the server produced deliberately (the service is healthy), so they are surfaced to the caller but do not trip the breaker, while server errors indicate an unhealthy service and do.Both examples are kept minimal and identical apart from the v1/v2 API differences.
Verification
gofmt,go vet ./...clean in both modulesgo test ./...passes in both the root andv2moduleshttptestharness (not committed): repeated 500s open the breaker (ErrOpenState), repeated 404s never do, and 2xx returns the body unchanged🤖 Generated with Claude Code