Skip to content

Commit

Permalink
Print out response body on error in sparkcli
Browse files Browse the repository at this point in the history
  • Loading branch information
BoYang committed May 18, 2022
1 parent f3d72b2 commit f3c1cbc
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion sparkcli/cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"crypto/tls"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"net/url"
Expand Down Expand Up @@ -61,7 +62,14 @@ func InsecureTLS(insecureSkipVerify bool) {
}

func ErrorBadHttpStatus(url string, response *http.Response) error {
return fmt.Errorf("got bad response from %s: %s", url, response.Status)
bytes, err := ioutil.ReadAll(response.Body)
str := ""
if err != nil {
str = err.Error()
} else {
str = string(bytes)
}
return fmt.Errorf("got bad response status %s from %s, response body: %s", response.Status, url, str)
}

func WriteOutputFileExitOnError(filePath string, fileContent string) {
Expand Down

0 comments on commit f3c1cbc

Please sign in to comment.