mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #17842 from henrybear327/gofail/show_req_error_msg
gofail: show error messages returned by gofail HTTP endpoints
This commit is contained in:
commit
2a8f77c99a
@ -375,7 +375,11 @@ func (f *BinaryFailpoints) SetupHTTP(ctx context.Context, failpoint, payload str
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
if resp.StatusCode != http.StatusNoContent {
|
if resp.StatusCode != http.StatusNoContent {
|
||||||
return fmt.Errorf("bad status code: %d", resp.StatusCode)
|
errMsg, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("bad status code: %d, err: %w", resp.StatusCode, err)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("bad status code: %d, err: %s", resp.StatusCode, errMsg)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -404,17 +408,18 @@ func (f *BinaryFailpoints) DeactivateHTTP(ctx context.Context, failpoint string)
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
if resp.StatusCode != http.StatusNoContent {
|
if resp.StatusCode != http.StatusNoContent {
|
||||||
return fmt.Errorf("bad status code: %d", resp.StatusCode)
|
errMsg, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("bad status code: %d, err: %w", resp.StatusCode, err)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("bad status code: %d, err: %s", resp.StatusCode, errMsg)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *BinaryFailpoints) Enabled() bool {
|
func (f *BinaryFailpoints) Enabled() bool {
|
||||||
_, err := failpoints(f.member)
|
_, err := failpoints(f.member)
|
||||||
if err != nil {
|
return err == nil
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *BinaryFailpoints) Available(failpoint string) bool {
|
func (f *BinaryFailpoints) Available(failpoint string) bool {
|
||||||
@ -449,8 +454,12 @@ func fetchFailpointsBody(member EtcdProcess) (io.ReadCloser, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
return nil, fmt.Errorf("invalid status code, %d", resp.StatusCode)
|
errMsg, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("invalid status code: %d, err: %w", resp.StatusCode, err)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("invalid status code: %d, err:%s", resp.StatusCode, errMsg)
|
||||||
}
|
}
|
||||||
return resp.Body, nil
|
return resp.Body, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user