diff --git a/osuapi/beatmapsets.go b/osuapi/beatmapsets.go index f52ed4a..ed0a36b 100644 --- a/osuapi/beatmapsets.go +++ b/osuapi/beatmapsets.go @@ -6,6 +6,8 @@ import ( "io/ioutil" "net/url" "os" + + "github.com/pkg/errors" ) func (api *Osuapi) SearchBeatmaps(rankStatus string) (beatmapSearch BeatmapSearch, err error) { @@ -15,7 +17,7 @@ func (api *Osuapi) SearchBeatmaps(rankStatus string) (beatmapSearch BeatmapSearc url := "/beatmapsets/search?" + query err = api.Request("GET", url, &beatmapSearch) if err != nil { - return + return errors.Wrap("failed to search beatmaps") } return diff --git a/osuapi/osuapi.go b/osuapi/osuapi.go index 8dbaaf0..adea136 100644 --- a/osuapi/osuapi.go +++ b/osuapi/osuapi.go @@ -11,6 +11,7 @@ import ( "sync" "time" + "github.com/pkg/errors" "golang.org/x/sync/semaphore" "subscribe-bot/config" @@ -73,17 +74,20 @@ func (api *Osuapi) Token() (token string, err error) { strings.NewReader(data), ) if err != nil { + err = errors.Wrap("failed to make POST request") return } var osuToken OsuToken respBody, err := ioutil.ReadAll(resp.Body) if err != nil { + err = errors.Wrap("failed to read response body") return } err = json.Unmarshal(respBody, &osuToken) if err != nil { + err = errors.Wrap("failed to unmarshal response body as json") return } @@ -106,16 +110,15 @@ func (api *Osuapi) Request0(action string, url string) (resp *http.Response, err token, err := api.Token() if err != nil { + err = errors.Wrap("failed to fetch token") return } req.Header.Add("Authorization", "Bearer "+token) - if err != nil { - return - } resp, err = api.httpClient.Do(req) if err != nil { + err = errors.Wrap("http client failed") return } @@ -141,17 +144,17 @@ func (api *Osuapi) Request0(action string, url string) (resp *http.Response, err func (api *Osuapi) Request(action string, url string, result interface{}) (err error) { resp, err := api.Request0(action, url) if err != nil { - return + return errors.Wrap("base request failed") } data, err := ioutil.ReadAll(resp.Body) if err != nil { - return + return errors.Wrap("failed to read http response body") } err = json.Unmarshal(data, result) if err != nil { - return + return errors.Wrap("failed to unmarshal http response as json") } return