You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I ran into an issue where I was calling GetUsers(...) and twitch was returning an error, but the helix library returned an empty error, so I didn't handle it right away.
In my program, I'm wrapping all error responses before I check for an error
funcGetHelixError(errerror, resp helix.ResponseCommon) error {
ifresp.ErrorStatus==0&&err==nil {
returnnil
}
iferr!=nil {
returnerr
}
returnfmt.Errorf("error %s with status %d: %s", resp.Error, resp.ErrorStatus, resp.ErrorMessage)
}
// Example calluserResp, err:=tokenClient.GetUsers(&helix.UsersParams{Logins: []string{strings.ToLower(botName)}})
err=service.GetHelixError(err, userResp.ResponseCommon)
iferr!=nil {
returnfmt.Errorf("could not get user info for bot %s: %w", botName, err)
}
Is the expected way to always check resp.ErrorStatus for it being set. This feels more a limitation of twitch not using proper status codes... but it's what we have to work with.
One thing that could be done, but it would require a lot of refactoring, is add a wrap function. Wrapping it on TwitchResponseError would allow a check with errors.Is(err, helix.TwitchResponseError)
varTwitchResponseError=errors.New("twitch returned an error")
funcpullErrorFromResponse(respResponseCommon) error {
ifresp.ErrorStatus==0 {
returnnil
}
returnfmt.Errorf("error %s occured with status %d and message %s: %w", resp.Error, resp.ErrorStatus, resp.ErrorMessage, err)
}
// elsewherefunc (c*Client) GetStreams(params*StreamsParams) (*StreamsResponse, error) {
resp, err:=c.get("/streams", &ManyStreams{}, params)
iferr!=nil {
returnnil, err
}
streams:=&StreamsResponse{}
resp.HydrateResponseCommon(&streams.ResponseCommon)
streams.Data.Streams=resp.Data.(*ManyStreams).Streamsstreams.Data.Pagination=resp.Data.(*ManyStreams).Pagination// refactor is here \/returnstreams, pullErrorFromResponse(resp.ResponseCommon)
}
The text was updated successfully, but these errors were encountered:
joeyak
changed the title
Endpoint error returns
Endpoint errors but returned error is nil
Dec 26, 2022
I ran into an issue where I was calling
GetUsers(...)
and twitch was returning an error, but the helix library returned an empty error, so I didn't handle it right away.In my program, I'm wrapping all error responses before I check for an error
Is the expected way to always check resp.ErrorStatus for it being set. This feels more a limitation of twitch not using proper status codes... but it's what we have to work with.
One thing that could be done, but it would require a lot of refactoring, is add a wrap function. Wrapping it on
TwitchResponseError
would allow a check witherrors.Is(err, helix.TwitchResponseError)
The text was updated successfully, but these errors were encountered: