mirror of
https://github.com/foomo/keel.git
synced 2025-10-16 12:35:34 +00:00
improved handling of disallowed reads from body
This commit is contained in:
parent
ba1a11b1ff
commit
f12379252f
@ -21,8 +21,13 @@ var (
|
||||
// needed
|
||||
ErrCircuitBreaker = errors.New("circuit breaker triggered")
|
||||
|
||||
// ErrIgnoreSuccessfulness
|
||||
// ErrIgnoreSuccessfulness can be returned by the IsSuccessful callback in order for the RoundTripware to ignore the
|
||||
// result of the function
|
||||
ErrIgnoreSuccessfulness = errors.New("ignored successfulness")
|
||||
|
||||
// ErrReadFromActualBody when it is attempted to read from a body in the IsSuccessful callback that has not
|
||||
// previously been copied.
|
||||
ErrReadFromActualBody = errors.New("read from actual body")
|
||||
)
|
||||
|
||||
// CircuitBreakerSettings is a copy of the gobreaker.Settings, except that the IsSuccessful function is omitted since we
|
||||
@ -184,7 +189,7 @@ func CircuitBreaker(set *CircuitBreakerSettings, opts ...CircuitBreakerOption) R
|
||||
// we actually want to return an error instead of the original request and error since the user
|
||||
// should be made aware that there is a misconfiguration
|
||||
resp = nil
|
||||
err = errSuccess
|
||||
err = ErrReadFromActualBody
|
||||
} else if !errors.Is(errSuccess, ErrIgnoreSuccessfulness) {
|
||||
done(errSuccess == nil)
|
||||
}
|
||||
|
||||
@ -230,6 +230,7 @@ func TestCircuitBreakerReadFromNotCopiedBodies(t *testing.T) {
|
||||
defer resp.Body.Close()
|
||||
}
|
||||
require.Error(t, err)
|
||||
require.ErrorIs(t, err, roundtripware.ErrReadFromActualBody)
|
||||
|
||||
// same thing for the response
|
||||
client = keelhttp.NewHTTPClient(
|
||||
@ -258,6 +259,7 @@ func TestCircuitBreakerReadFromNotCopiedBodies(t *testing.T) {
|
||||
defer resp.Body.Close()
|
||||
}
|
||||
require.Error(t, err)
|
||||
require.ErrorIs(t, err, roundtripware.ErrReadFromActualBody)
|
||||
}
|
||||
|
||||
func TestCircuitBreakerInterval(t *testing.T) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user