mirror of
https://github.com/mrusme/neonmodem.git
synced 2025-02-02 15:07:59 -05:00
Added descriptive error messages for discourse
This commit is contained in:
parent
0c5be5df5f
commit
acfb0ece2a
@ -8,6 +8,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/hashicorp/go-retryablehttp"
|
"github.com/hashicorp/go-retryablehttp"
|
||||||
)
|
)
|
||||||
@ -145,6 +146,10 @@ func (c *Client) NewRequest(
|
|||||||
return req, nil
|
return req, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ErrorBody struct {
|
||||||
|
Errors []string `json:"errors"`
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) Do(
|
func (c *Client) Do(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
req *http.Request,
|
req *http.Request,
|
||||||
@ -180,8 +185,15 @@ func (c *Client) Do(
|
|||||||
|
|
||||||
if res.StatusCode < http.StatusOK ||
|
if res.StatusCode < http.StatusOK ||
|
||||||
res.StatusCode > http.StatusNoContent {
|
res.StatusCode > http.StatusNoContent {
|
||||||
|
var errbody ErrorBody
|
||||||
|
if err := json.Unmarshal(body, &errbody); err == nil {
|
||||||
|
return &RequestError{
|
||||||
|
Err: errors.New(strings.Join(errbody.Errors, "\n")),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return &RequestError{
|
return &RequestError{
|
||||||
Err: errors.New("Non-2xx status code"),
|
Err: errors.New(string(body)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user