mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-08-22 18:36:16 +00:00
Add response body to the error in case of failure (#503)
* add response body to the error in case of failure * fix typo + make inline condition
This commit is contained in:
parent
1c18eb1b84
commit
b0c8c0c192
@ -3,11 +3,12 @@ package apiserver
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/up9inc/mizu/shared/kubernetes"
|
||||
@ -61,7 +62,14 @@ func (provider *Provider) GetHealthStatus() (*shared.HealthResponse, error) {
|
||||
if response, err := provider.client.Get(healthUrl); err != nil {
|
||||
return nil, err
|
||||
} else if response.StatusCode > 299 {
|
||||
return nil, errors.New(fmt.Sprintf("status code: %d", response.StatusCode))
|
||||
responseBody := new(strings.Builder)
|
||||
|
||||
if _, err := io.Copy(responseBody, response.Body); err != nil {
|
||||
return nil, fmt.Errorf("status code: %d - (bad response - %v)", response.StatusCode, err)
|
||||
} else {
|
||||
singleLineResponse := strings.ReplaceAll(responseBody.String(), "\n", "")
|
||||
return nil, fmt.Errorf("status code: %d - (response - %v)", response.StatusCode, singleLineResponse)
|
||||
}
|
||||
} else {
|
||||
defer response.Body.Close()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user