Use resty response.IsSuccess() instead of checking for status code 200

This commit is contained in:
Philipp Wolfer 2024-03-24 16:36:53 +01:00
parent 3f1bebd8ed
commit 357932f9b0
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
5 changed files with 12 additions and 12 deletions

View file

@ -85,7 +85,7 @@ func listRequest[T Result](c Client, path string, offset int, limit int) (result
} }
response, err := request.Get(path) response, err := request.Get(path)
if response.StatusCode() != 200 { if !response.IsSuccess() {
err = errors.New(response.String()) err = errors.New(response.String())
} else if result.Error() != nil { } else if result.Error() != nil {
err = errors.New(result.Error().Message) err = errors.New(result.Error().Message)

View file

@ -66,7 +66,7 @@ func (c Client) GetHistoryListenings(user string, page int, perPage int) (result
SetResult(&result). SetResult(&result).
Get(path) Get(path)
if response.StatusCode() != 200 { if !response.IsSuccess() {
err = errors.New(response.String()) err = errors.New(response.String())
return return
} }
@ -84,7 +84,7 @@ func (c Client) GetFavoriteTracks(page int, perPage int) (result FavoriteTracksR
SetResult(&result). SetResult(&result).
Get(path) Get(path)
if response.StatusCode() != 200 { if !response.IsSuccess() {
err = errors.New(response.String()) err = errors.New(response.String())
return return
} }

View file

@ -74,7 +74,7 @@ func (c Client) GetListens(user string, maxTime time.Time, minTime time.Time) (r
SetError(&errorResult). SetError(&errorResult).
Get(path) Get(path)
if response.StatusCode() != 200 { if !response.IsSuccess() {
err = errors.New(errorResult.Error) err = errors.New(errorResult.Error)
return return
} }
@ -90,7 +90,7 @@ func (c Client) SubmitListens(listens ListenSubmission) (result StatusResult, er
SetError(&errorResult). SetError(&errorResult).
Post(path) Post(path)
if response.StatusCode() != 200 { if !response.IsSuccess() {
err = errors.New(errorResult.Error) err = errors.New(errorResult.Error)
return return
} }
@ -112,7 +112,7 @@ func (c Client) GetFeedback(user string, status int, offset int) (result GetFeed
SetError(&errorResult). SetError(&errorResult).
Get(path) Get(path)
if response.StatusCode() != 200 { if !response.IsSuccess() {
err = errors.New(errorResult.Error) err = errors.New(errorResult.Error)
return return
} }
@ -128,7 +128,7 @@ func (c Client) SendFeedback(feedback Feedback) (result StatusResult, err error)
SetError(&errorResult). SetError(&errorResult).
Post(path) Post(path)
if response.StatusCode() != 200 { if !response.IsSuccess() {
err = errors.New(errorResult.Error) err = errors.New(errorResult.Error)
return return
} }
@ -147,7 +147,7 @@ func (c Client) Lookup(recordingName string, artistName string) (result LookupRe
SetError(&errorResult). SetError(&errorResult).
Get(path) Get(path)
if response.StatusCode() != 200 { if !response.IsSuccess() {
err = errors.New(errorResult.Error) err = errors.New(errorResult.Error)
return return
} }

View file

@ -58,7 +58,7 @@ func (c Client) GetScrobbles(page int, perPage int) (result GetScrobblesResult,
SetResult(&result). SetResult(&result).
Get(path) Get(path)
if response.StatusCode() != 200 { if !response.IsSuccess() {
err = errors.New(response.String()) err = errors.New(response.String())
return return
} }
@ -73,7 +73,7 @@ func (c Client) NewScrobble(scrobble NewScrobble) (result NewScrobbleResult, err
SetResult(&result). SetResult(&result).
Post(path) Post(path)
if response.StatusCode() != 200 { if !response.IsSuccess() {
err = errors.New(response.String()) err = errors.New(response.String())
return return
} }

View file

@ -79,7 +79,7 @@ func (c Client) recentlyPlayed(after *time.Time, before *time.Time, limit int) (
} }
response, err := request.Get(path) response, err := request.Get(path)
if response.StatusCode() != 200 { if !response.IsSuccess() {
err = errors.New(response.String()) err = errors.New(response.String())
} }
return return
@ -95,7 +95,7 @@ func (c Client) UserTracks(offset int, limit int) (result TracksResult, err erro
SetResult(&result). SetResult(&result).
Get(path) Get(path)
if response.StatusCode() != 200 { if !response.IsSuccess() {
err = errors.New(response.String()) err = errors.New(response.String())
} }
return return