return error message from instance to the user
This commit is contained in:
parent
e5eb2d72a8
commit
b39150175c
1 changed files with 22 additions and 1 deletions
|
@ -123,9 +123,30 @@ func (g *Client) sendRequest(method string, url string, requestBody io.Reader, o
|
||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
|
|
||||||
if response.StatusCode < http.StatusOK || response.StatusCode >= http.StatusBadRequest {
|
if response.StatusCode < http.StatusOK || response.StatusCode >= http.StatusBadRequest {
|
||||||
|
message := struct {
|
||||||
|
Error string `json:"error"`
|
||||||
|
}{
|
||||||
|
Error: "",
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := json.NewDecoder(response.Body).Decode(&message); err != nil {
|
||||||
|
return fmt.Errorf(
|
||||||
|
"did not receive an OK response from the GoToSocial server: got %d",
|
||||||
|
response.StatusCode,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if message.Error == "" {
|
||||||
|
return fmt.Errorf(
|
||||||
|
"did not receive an OK response from the GoToSocial server: got %d",
|
||||||
|
response.StatusCode,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"did not receive an OK response from the GoToSocial server: got %d",
|
"message received from the instance: (%d) %q",
|
||||||
response.StatusCode,
|
response.StatusCode,
|
||||||
|
message.Error,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue