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,12 +123,33 @@ func (g *Client) sendRequest(method string, url string, requestBody io.Reader, o
|
|||
defer response.Body.Close()
|
||||
|
||||
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(
|
||||
"message received from the instance: (%d) %q",
|
||||
response.StatusCode,
|
||||
message.Error,
|
||||
)
|
||||
}
|
||||
|
||||
if object == nil {
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue