mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-08-23 11:02:35 +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 (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/up9inc/mizu/shared/kubernetes"
|
"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 {
|
if response, err := provider.client.Get(healthUrl); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if response.StatusCode > 299 {
|
} 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 {
|
} else {
|
||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user