From b11a712ecc15828bae1e5681105ce5b6044e2ae9 Mon Sep 17 00:00:00 2001 From: Evan Fiordeliso Date: Thu, 7 Mar 2024 19:41:05 -0500 Subject: [PATCH] Add http status handling to all endpoint requests --- api/ads/get_ad_schedule.go | 7 ++++++- api/ads/snooze_next_ad.go | 7 ++++++- api/ads/start_commercial.go | 7 ++++++- api/analytics/get_extension_analytics.go | 7 ++++++- api/analytics/get_game_analytics.go | 7 ++++++- api/bits/get_bits_leaderboard.go | 7 ++++++- api/bits/get_cheermotes.go | 7 ++++++- api/bits/get_extension_transactions.go | 7 ++++++- api/ccls/get_content_classification_labels.go | 6 ++++++ api/channelpoints/create_custom_rewards.go | 7 ++++++- api/channelpoints/delete_custom_reward.go | 7 ++++++- api/channelpoints/get_custom_reward.go | 7 ++++++- api/channelpoints/get_custom_reward_redemption.go | 7 ++++++- api/channelpoints/update_custom_reward.go | 7 ++++++- api/channelpoints/update_redemption_status.go | 7 ++++++- api/channels/get_channel_editors.go | 7 ++++++- api/channels/get_channel_followers.go | 7 ++++++- api/channels/get_channel_information.go | 7 ++++++- api/channels/get_followed_channels.go | 6 ++++++ api/channels/modify_channel_information.go | 10 +++++++++- api/charity/get_charity_campaign.go | 6 ++++++ api/charity/get_charity_campaign_donations.go | 7 +++++++ api/chat/get_channel_chat_badges.go | 6 ++++++ api/chat/get_channel_emotes.go | 12 +++++++++--- api/chat/get_chat_settings.go | 6 ++++++ api/chat/get_chatters.go | 12 +++++++++--- api/chat/get_emote_sets.go | 6 ++++++ api/chat/get_global_chat_badges.go | 6 ++++++ api/chat/get_global_emotes.go | 6 ++++++ api/chat/get_user_chat_color.go | 6 ++++++ api/chat/send_chat_announcement.go | 6 ++++++ api/chat/send_chat_message.go | 6 ++++++ api/chat/send_shoutout.go | 6 ++++++ api/chat/update_chat_settings.go | 6 ++++++ api/chat/update_user_chat_color.go | 6 ++++++ api/conduit/create_conduits.go | 6 ++++++ api/conduit/delete_conduit.go | 6 ++++++ api/conduit/get_conduit_shards.go | 6 ++++++ api/conduit/get_conduits.go | 6 ++++++ api/conduit/update_conduit_shards.go | 6 ++++++ api/conduit/update_conduits.go | 6 ++++++ api/entitlements/get_drops_entitlements.go | 7 +++++++ api/entitlements/update_drops_entitlements.go | 7 +++++++ api/eventsub/create_eventsub_subscription.go | 6 ++++++ api/eventsub/delete_eventsub_subscription.go | 10 +++++++++- api/eventsub/get_eventsub_subscriptions.go | 6 ++++++ api/extensions/create_extension_secret.go | 6 ++++++ api/extensions/get_extension_bits_products.go | 6 ++++++ .../get_extension_configuration_segment.go | 6 ++++++ api/extensions/get_extension_live_channels.go | 6 ++++++ api/extensions/get_extension_secrets.go | 6 ++++++ api/extensions/get_extensions.go | 6 ++++++ api/extensions/get_released_extensions.go | 6 ++++++ api/extensions/send_extension_chat_message.go | 6 ++++++ api/extensions/send_extension_pubsub_message.go | 6 ++++++ .../set_extension_configuration_segment.go | 6 ++++++ .../set_extension_required_configuration.go | 6 ++++++ api/extensions/update_extension_bits_product.go | 6 ++++++ api/games/get_games.go | 6 ++++++ api/games/get_top_games.go | 6 ++++++ api/goals/get_creator_goals.go | 6 ++++++ api/gueststar/assign_gueststar_slot.go | 6 ++++++ api/gueststar/create_gueststar_session.go | 6 ++++++ api/gueststar/delete_gueststar_invite.go | 6 ++++++ api/gueststar/delete_gueststar_slot.go | 6 ++++++ api/gueststar/end_gueststar_session.go | 6 ++++++ api/gueststar/get_channel_gueststar_settings.go | 6 ++++++ api/gueststar/get_gueststar_invites.go | 6 ++++++ api/gueststar/get_gueststar_session.go | 6 ++++++ api/gueststar/send_gueststar_invite.go | 6 ++++++ api/gueststar/update_channel_gueststar_settings.go | 6 ++++++ api/gueststar/update_gueststar_slot.go | 6 ++++++ api/gueststar/update_gueststar_slot_settings.go | 6 ++++++ api/hypetrain/get_hypetrain_events.go | 6 ++++++ api/moderation/add_blocked_term.go | 6 ++++++ api/moderation/add_channel_moderator.go | 6 ++++++ api/moderation/add_channel_vip.go | 6 ++++++ api/moderation/ban_user.go | 6 ++++++ api/moderation/check_automod_status.go | 6 ++++++ api/moderation/delete_chat_messages.go | 6 ++++++ api/moderation/get_automod_settings.go | 6 ++++++ api/moderation/get_banned_users.go | 6 ++++++ api/moderation/get_blocked_terms.go | 6 ++++++ api/moderation/get_moderated_channels.go | 6 ++++++ api/moderation/get_moderators.go | 6 ++++++ api/moderation/get_shield_mode_status.go | 6 ++++++ api/moderation/get_vips.go | 7 +++++++ api/moderation/manage_held_automod_messages.go | 6 ++++++ api/moderation/remove_blocked_term.go | 6 ++++++ api/moderation/remove_channel_moderator.go | 6 ++++++ api/moderation/remove_channel_vip.go | 6 ++++++ api/moderation/unban_user.go | 6 ++++++ api/moderation/update_automod_settings.go | 6 ++++++ api/moderation/update_shield_mode_status.go | 6 ++++++ api/polls/create_poll.go | 6 ++++++ api/polls/end_poll.go | 6 ++++++ api/polls/get_polls.go | 6 ++++++ api/predictions/create_prediction.go | 6 ++++++ api/predictions/end_prediction.go | 6 ++++++ api/predictions/get_predictions.go | 6 ++++++ api/raids/cancel_a_raid.go | 6 ++++++ api/raids/start_a_raid.go | 6 ++++++ .../create_channel_stream_schedule_segment.go | 6 ++++++ .../delete_channel_stream_schedule_segment.go | 6 ++++++ api/schedule/get_channel_stream_schedule.go | 6 ++++++ api/schedule/update_channel_stream_schedule.go | 6 ++++++ .../update_channel_stream_schedule_segment.go | 6 ++++++ api/search/search_categories.go | 6 ++++++ api/search/search_channels.go | 6 ++++++ api/streams/create_stream_marker.go | 6 ++++++ api/streams/get_followed_streams.go | 6 ++++++ api/streams/get_stream_key.go | 6 ++++++ api/streams/get_stream_markers.go | 6 ++++++ api/streams/get_streams.go | 6 ++++++ api/subscriptions/check_user_subscription.go | 6 ++++++ api/subscriptions/get_broadcaster_subscriptions.go | 6 ++++++ api/teams/get_channel_teams.go | 6 ++++++ api/teams/get_teams.go | 6 ++++++ api/users/block_user.go | 6 ++++++ api/users/get_user_active_extensions.go | 6 ++++++ api/users/get_user_block_list.go | 6 ++++++ api/users/get_user_extensions.go | 6 ++++++ api/users/get_users.go | 12 +++++------- api/users/unblock_user.go | 6 ++++++ api/users/update_user.go | 6 ++++++ api/users/update_user_extensions.go | 6 ++++++ api/videos/delete_videos.go | 6 ++++++ api/videos/get_videos.go | 6 ++++++ api/whispers/send_whisper.go | 6 ++++++ auth/token.go | 6 ++++++ 130 files changed, 795 insertions(+), 32 deletions(-) diff --git a/api/ads/get_ad_schedule.go b/api/ads/get_ad_schedule.go index 5c7feba..9341019 100644 --- a/api/ads/get_ad_schedule.go +++ b/api/ads/get_ad_schedule.go @@ -3,6 +3,7 @@ package ads import ( "context" "encoding/json" + "fmt" "net/http" "net/url" "time" @@ -50,9 +51,13 @@ func (e *Ads) GetAdSchedule(ctx context.Context, broadcasterID string) (*GetAdSc if err != nil { return nil, err } - defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get ad schedule (%d)", res.StatusCode) + } + var data GetAdScheduleResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/ads/snooze_next_ad.go b/api/ads/snooze_next_ad.go index ca6b0f7..3a867dc 100644 --- a/api/ads/snooze_next_ad.go +++ b/api/ads/snooze_next_ad.go @@ -3,6 +3,7 @@ package ads import ( "context" "encoding/json" + "fmt" "net/http" "net/url" "time" @@ -41,9 +42,13 @@ func (e *Ads) SnoozeNextAd(ctx context.Context, broadcasterID string) (*SnoozeNe if err != nil { return nil, err } - defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to snooze next ad (%d)", res.StatusCode) + } + var data SnoozeNextAdResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/ads/start_commercial.go b/api/ads/start_commercial.go index 6053dbb..799d895 100644 --- a/api/ads/start_commercial.go +++ b/api/ads/start_commercial.go @@ -3,6 +3,7 @@ package ads import ( "context" "encoding/json" + "fmt" "io" "net/http" "net/url" @@ -63,9 +64,13 @@ func (e *Ads) StartCommercial(ctx context.Context, body *StartCommercialRequest) if err != nil { return nil, err } - defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to start commercial (%d)", res.StatusCode) + } + var data StartCommercialResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/analytics/get_extension_analytics.go b/api/analytics/get_extension_analytics.go index a19e1ce..1248295 100644 --- a/api/analytics/get_extension_analytics.go +++ b/api/analytics/get_extension_analytics.go @@ -3,6 +3,7 @@ package analytics import ( "context" "encoding/json" + "fmt" "net/http" "net/url" "time" @@ -93,9 +94,13 @@ func (e *Analytics) GetExtensionAnalytics(ctx context.Context, params GetExtensi if err != nil { return nil, err } - defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get extension analytics (%d)", res.StatusCode) + } + var data GetExtensionAnalyticsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/analytics/get_game_analytics.go b/api/analytics/get_game_analytics.go index 4a78713..0624c72 100644 --- a/api/analytics/get_game_analytics.go +++ b/api/analytics/get_game_analytics.go @@ -3,6 +3,7 @@ package analytics import ( "context" "encoding/json" + "fmt" "net/http" "net/url" "time" @@ -94,9 +95,13 @@ func (e *Analytics) GetGameAnalytics(ctx context.Context, params GetGameAnalytic if err != nil { return nil, err } - defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get game analytics (%d)", res.StatusCode) + } + var data GetGameAnalyticsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/bits/get_bits_leaderboard.go b/api/bits/get_bits_leaderboard.go index 2d8864d..e091897 100644 --- a/api/bits/get_bits_leaderboard.go +++ b/api/bits/get_bits_leaderboard.go @@ -3,6 +3,7 @@ package bits import ( "context" "encoding/json" + "fmt" "net/http" "net/url" "time" @@ -81,9 +82,13 @@ func (b *Bits) GetBitsLeaderboard(ctx context.Context, params *GetBitsLeaderboar if err != nil { return nil, err } - defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get bits leaderboard (%d)", res.StatusCode) + } + var data GetBitsLeaderboardResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/bits/get_cheermotes.go b/api/bits/get_cheermotes.go index ed07706..5baf726 100644 --- a/api/bits/get_cheermotes.go +++ b/api/bits/get_cheermotes.go @@ -3,6 +3,7 @@ package bits import ( "context" "encoding/json" + "fmt" "net/http" "net/url" "time" @@ -93,9 +94,13 @@ func (b *Bits) GetCheermotes(ctx context.Context, broadcasterID string) (*GetChe if err != nil { return nil, err } - defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get cheermotes (%d)", res.StatusCode) + } + var data GetCheermotesResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/bits/get_extension_transactions.go b/api/bits/get_extension_transactions.go index bbe03b3..646a708 100644 --- a/api/bits/get_extension_transactions.go +++ b/api/bits/get_extension_transactions.go @@ -3,6 +3,7 @@ package bits import ( "context" "encoding/json" + "fmt" "net/http" "net/url" "time" @@ -108,9 +109,13 @@ func (b *Bits) GetExtensionTransactions(ctx context.Context, params *GetExtensio if err != nil { return nil, err } - defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get extension transactions (%d)", res.StatusCode) + } + var data GetExtensionTransactionsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/ccls/get_content_classification_labels.go b/api/ccls/get_content_classification_labels.go index d9b35a7..67c24ae 100644 --- a/api/ccls/get_content_classification_labels.go +++ b/api/ccls/get_content_classification_labels.go @@ -3,6 +3,7 @@ package ccls import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -51,6 +52,11 @@ func (c *CCLS) GetContentClassificationLabels(ctx context.Context, params GetCon } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get content classification labels (%d)", res.StatusCode) + } + var data GetContentClassificationLabelsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/channelpoints/create_custom_rewards.go b/api/channelpoints/create_custom_rewards.go index 90760c9..e7eb57d 100644 --- a/api/channelpoints/create_custom_rewards.go +++ b/api/channelpoints/create_custom_rewards.go @@ -3,6 +3,7 @@ package channelpoints import ( "context" "encoding/json" + "fmt" "io" "net/http" "net/url" @@ -91,9 +92,13 @@ func (c *ChannelPoints) CreateCustomRewards(ctx context.Context, broadcastID str if err != nil { return nil, err } - defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to create custom rewards (%d)", res.StatusCode) + } + var data CreateCustomRewardsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/channelpoints/delete_custom_reward.go b/api/channelpoints/delete_custom_reward.go index e5cc4d3..a8848e4 100644 --- a/api/channelpoints/delete_custom_reward.go +++ b/api/channelpoints/delete_custom_reward.go @@ -2,6 +2,7 @@ package channelpoints import ( "context" + "fmt" "net/http" "net/url" @@ -35,8 +36,12 @@ func (c *ChannelPoints) DeleteCustomReward(ctx context.Context, params *DeleteCu if err != nil { return err } - defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return fmt.Errorf("failed to delete custom reward (%d)", res.StatusCode) + } + return nil } diff --git a/api/channelpoints/get_custom_reward.go b/api/channelpoints/get_custom_reward.go index 1e285b0..118b8ca 100644 --- a/api/channelpoints/get_custom_reward.go +++ b/api/channelpoints/get_custom_reward.go @@ -3,6 +3,7 @@ package channelpoints import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -48,9 +49,13 @@ func (c *ChannelPoints) GetCustomReward(ctx context.Context, params *GetCustomRe if err != nil { return nil, err } - defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get custom rewards (%d)", res.StatusCode) + } + var data GetCustomRewardResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/channelpoints/get_custom_reward_redemption.go b/api/channelpoints/get_custom_reward_redemption.go index 10873cd..a690630 100644 --- a/api/channelpoints/get_custom_reward_redemption.go +++ b/api/channelpoints/get_custom_reward_redemption.go @@ -3,6 +3,7 @@ package channelpoints import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -64,9 +65,13 @@ func (c *ChannelPoints) GetCustomRewardRedemption(ctx context.Context, params *G if err != nil { return nil, err } - defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get custom reward redemptions (%d)", res.StatusCode) + } + var data GetCustomRewardRedemptionResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/channelpoints/update_custom_reward.go b/api/channelpoints/update_custom_reward.go index f0b3359..71381e7 100644 --- a/api/channelpoints/update_custom_reward.go +++ b/api/channelpoints/update_custom_reward.go @@ -3,6 +3,7 @@ package channelpoints import ( "context" "encoding/json" + "fmt" "io" "net/http" "net/url" @@ -103,9 +104,13 @@ func (c *ChannelPoints) UpdateCustomReward(ctx context.Context, params *UpdateCu if err != nil { return nil, err } - defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to update custom reward (%d)", res.StatusCode) + } + var data UpdateCustomRewardResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/channelpoints/update_redemption_status.go b/api/channelpoints/update_redemption_status.go index 208bf86..765dd4b 100644 --- a/api/channelpoints/update_redemption_status.go +++ b/api/channelpoints/update_redemption_status.go @@ -3,6 +3,7 @@ package channelpoints import ( "context" "encoding/json" + "fmt" "io" "net/http" "net/url" @@ -63,9 +64,13 @@ func (c *ChannelPoints) UpdateRedemptionStatus(ctx context.Context, params *Upda if err != nil { return nil, err } - defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to update redemption status (%d)", res.StatusCode) + } + var data UpdateRedemptionStatusResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/channels/get_channel_editors.go b/api/channels/get_channel_editors.go index 4128289..597e128 100644 --- a/api/channels/get_channel_editors.go +++ b/api/channels/get_channel_editors.go @@ -3,6 +3,7 @@ package channels import ( "context" "encoding/json" + "fmt" "net/http" "net/url" "time" @@ -39,9 +40,13 @@ func (c *Channels) GetChannelEditors(ctx context.Context, broadcasterID string) if err != nil { return nil, err } - defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get channel editors (%d)", res.StatusCode) + } + var data GetChannelEditorsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/channels/get_channel_followers.go b/api/channels/get_channel_followers.go index 0f8d8f8..d080f84 100644 --- a/api/channels/get_channel_followers.go +++ b/api/channels/get_channel_followers.go @@ -3,6 +3,7 @@ package channels import ( "context" "encoding/json" + "fmt" "net/http" "net/url" "time" @@ -82,9 +83,13 @@ func (c *Channels) GetChannelFollowers(ctx context.Context, params *GetChannelFo if err != nil { return nil, err } - defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get channel followers (%d)", res.StatusCode) + } + var data GetChannelFollowersResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/channels/get_channel_information.go b/api/channels/get_channel_information.go index f167536..28e2641 100644 --- a/api/channels/get_channel_information.go +++ b/api/channels/get_channel_information.go @@ -3,6 +3,7 @@ package channels import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -81,9 +82,13 @@ func (c *Channels) GetChannelInformation(ctx context.Context, params *GetChannel if err != nil { return nil, err } - defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get channel information (%d)", res.StatusCode) + } + var data GetChannelInformdationResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/channels/get_followed_channels.go b/api/channels/get_followed_channels.go index c9a74bb..0f61ed9 100644 --- a/api/channels/get_followed_channels.go +++ b/api/channels/get_followed_channels.go @@ -3,6 +3,7 @@ package channels import ( "context" "encoding/json" + "fmt" "net/http" "net/url" "time" @@ -76,6 +77,11 @@ func (c *Channels) GetFollowedChannels(ctx context.Context, params *GetFollowedC defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get followed channels (%d)", res.StatusCode) + } + var data GetFollowedChannelsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/channels/modify_channel_information.go b/api/channels/modify_channel_information.go index e868655..f542c56 100644 --- a/api/channels/modify_channel_information.go +++ b/api/channels/modify_channel_information.go @@ -3,6 +3,7 @@ package channels import ( "context" "encoding/json" + "fmt" "io" "net/http" "net/url" @@ -71,9 +72,16 @@ func (c *Channels) ModifyChannelInformation(ctx context.Context, broadcasterID s return err } - if _, err := c.client.Do(req); err != nil { + res, err := c.client.Do(req) + if err != nil { return err } + defer res.Body.Close() + + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return fmt.Errorf("failed to modify channel information (%d)", res.StatusCode) + } return nil } diff --git a/api/charity/get_charity_campaign.go b/api/charity/get_charity_campaign.go index ee6f3b0..a68fa7b 100644 --- a/api/charity/get_charity_campaign.go +++ b/api/charity/get_charity_campaign.go @@ -3,6 +3,7 @@ package charity import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -69,6 +70,11 @@ func (c *Charity) GetCharityCampaign(ctx context.Context, broadcasterID string) defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get charity campaign (%d)", res.StatusCode) + } + var data GetCharityCampaignResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/charity/get_charity_campaign_donations.go b/api/charity/get_charity_campaign_donations.go index 58e99b2..198e7db 100644 --- a/api/charity/get_charity_campaign_donations.go +++ b/api/charity/get_charity_campaign_donations.go @@ -3,6 +3,7 @@ package charity import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -71,6 +72,12 @@ func (c *Charity) GetCharityCampaignDonations(ctx context.Context, params *GetCh if err != nil { return nil, err } + defer res.Body.Close() + + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get charity campaign donations (%d)", res.StatusCode) + } var respBody GetCharityCampaignDonationsResponse if err := json.NewDecoder(res.Body).Decode(&respBody); err != nil { diff --git a/api/chat/get_channel_chat_badges.go b/api/chat/get_channel_chat_badges.go index 4e088bd..202ecda 100644 --- a/api/chat/get_channel_chat_badges.go +++ b/api/chat/get_channel_chat_badges.go @@ -3,6 +3,7 @@ package chat import ( "context" "encoding/json" + "fmt" "net/http" "net/url" ) @@ -32,6 +33,11 @@ func (c *Chat) GetChannelChatBadges(ctx context.Context, broadcasterID string) ( } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get channel chat badges (%d)", res.StatusCode) + } + var data GetChannelChatBadgesResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/chat/get_channel_emotes.go b/api/chat/get_channel_emotes.go index 54b0e0d..a08d951 100644 --- a/api/chat/get_channel_emotes.go +++ b/api/chat/get_channel_emotes.go @@ -3,6 +3,7 @@ package chat import ( "context" "encoding/json" + "fmt" "net/http" "net/url" ) @@ -95,14 +96,19 @@ func (c *Chat) GetChannelEmotes(ctx context.Context, broadcasterID string) (*Get return nil, err } - resp, err := c.client.Do(req) + res, err := c.client.Do(req) if err != nil { return nil, err } - defer resp.Body.Close() + defer res.Body.Close() + + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get channel emotes (%d)", res.StatusCode) + } var response GetChannelEmotesResponse - if err := json.NewDecoder(resp.Body).Decode(&response); err != nil { + if err := json.NewDecoder(res.Body).Decode(&response); err != nil { return nil, err } diff --git a/api/chat/get_chat_settings.go b/api/chat/get_chat_settings.go index efa1362..cc3b4c9 100644 --- a/api/chat/get_chat_settings.go +++ b/api/chat/get_chat_settings.go @@ -3,6 +3,7 @@ package chat import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -48,6 +49,11 @@ func (c *Chat) GetChatSettings(ctx context.Context, params *GetChatSettingsParam } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get chat settings (%d)", res.StatusCode) + } + var data GetChatSettingsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/chat/get_chatters.go b/api/chat/get_chatters.go index c21ceec..179ef36 100644 --- a/api/chat/get_chatters.go +++ b/api/chat/get_chatters.go @@ -3,6 +3,7 @@ package chat import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -69,14 +70,19 @@ func (c *Chat) GetChatters(ctx context.Context, params *GetChattersParams) (*Get return nil, err } - resp, err := c.client.Do(req) + res, err := c.client.Do(req) if err != nil { return nil, err } - defer resp.Body.Close() + defer res.Body.Close() + + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get chatters (%d)", res.StatusCode) + } var response GetChattersResponse - if err := json.NewDecoder(resp.Body).Decode(&response); err != nil { + if err := json.NewDecoder(res.Body).Decode(&response); err != nil { return nil, err } diff --git a/api/chat/get_emote_sets.go b/api/chat/get_emote_sets.go index e3fee81..25ba93c 100644 --- a/api/chat/get_emote_sets.go +++ b/api/chat/get_emote_sets.go @@ -3,6 +3,7 @@ package chat import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -107,6 +108,11 @@ func (c *Chat) GetEmoteSets(ctx context.Context, params *GetEmoteSetsParams) (*G } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get emote sets (%d)", res.StatusCode) + } + var data GetEmoteSetsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/chat/get_global_chat_badges.go b/api/chat/get_global_chat_badges.go index d59eadc..0013b12 100644 --- a/api/chat/get_global_chat_badges.go +++ b/api/chat/get_global_chat_badges.go @@ -3,6 +3,7 @@ package chat import ( "context" "encoding/json" + "fmt" "net/http" "net/url" ) @@ -30,6 +31,11 @@ func (c *Chat) GetGlobalChatBadges(ctx context.Context) (*GetGlobalChatBadgesRes } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get global chat badges (%d)", res.StatusCode) + } + var data GetGlobalChatBadgesResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/chat/get_global_emotes.go b/api/chat/get_global_emotes.go index ab1c713..bf14ac5 100644 --- a/api/chat/get_global_emotes.go +++ b/api/chat/get_global_emotes.go @@ -3,6 +3,7 @@ package chat import ( "context" "encoding/json" + "fmt" "net/http" "net/url" ) @@ -77,6 +78,11 @@ func (c *Chat) GetGlobalEmotes(ctx context.Context) (*GetGlobalEmotesResponse, e } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get global emotes (%d)", res.StatusCode) + } + var data GetGlobalEmotesResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/chat/get_user_chat_color.go b/api/chat/get_user_chat_color.go index 2148b79..731e5f1 100644 --- a/api/chat/get_user_chat_color.go +++ b/api/chat/get_user_chat_color.go @@ -3,6 +3,7 @@ package chat import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -56,6 +57,11 @@ func (c *Chat) GetUserChatColor(ctx context.Context, params *GetUserChatColorPar } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get user chat color (%d)", res.StatusCode) + } + var data GetUserChatColorResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/chat/send_chat_announcement.go b/api/chat/send_chat_announcement.go index c9e2e3d..1535ff8 100644 --- a/api/chat/send_chat_announcement.go +++ b/api/chat/send_chat_announcement.go @@ -3,6 +3,7 @@ package chat import ( "context" "encoding/json" + "fmt" "io" "net/http" "net/url" @@ -60,5 +61,10 @@ func (c *Chat) SendChatAnnouncement(ctx context.Context, params *SendChatAnnounc } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return fmt.Errorf("failed to send chat announcement (%d)", res.StatusCode) + } + return nil } diff --git a/api/chat/send_chat_message.go b/api/chat/send_chat_message.go index 5b27539..d6f976d 100644 --- a/api/chat/send_chat_message.go +++ b/api/chat/send_chat_message.go @@ -3,6 +3,7 @@ package chat import ( "context" "encoding/json" + "fmt" "io" "net/http" "net/url" @@ -76,6 +77,11 @@ func (c *Chat) SendChatMessage(ctx context.Context, body *SendChatMessageRequest } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to send chat message (%d)", res.StatusCode) + } + var data SendChatMessageResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/chat/send_shoutout.go b/api/chat/send_shoutout.go index 869c745..f79254d 100644 --- a/api/chat/send_shoutout.go +++ b/api/chat/send_shoutout.go @@ -2,6 +2,7 @@ package chat import ( "context" + "fmt" "net/http" "net/url" @@ -51,5 +52,10 @@ func (c *Chat) SendShoutout(ctx context.Context, params *SendShoutoutParams) err } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return fmt.Errorf("failed to send shoutout (%d)", res.StatusCode) + } + return nil } diff --git a/api/chat/update_chat_settings.go b/api/chat/update_chat_settings.go index 25519d5..b7693f3 100644 --- a/api/chat/update_chat_settings.go +++ b/api/chat/update_chat_settings.go @@ -3,6 +3,7 @@ package chat import ( "context" "encoding/json" + "fmt" "io" "net/http" "net/url" @@ -116,6 +117,11 @@ func (c *Chat) UpdateChatSettings(ctx context.Context, params *UpdateChatSetting } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to update chat settings (%d)", res.StatusCode) + } + var data UpdateChatSettingsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/chat/update_user_chat_color.go b/api/chat/update_user_chat_color.go index cbcbc98..c1a6b79 100644 --- a/api/chat/update_user_chat_color.go +++ b/api/chat/update_user_chat_color.go @@ -2,6 +2,7 @@ package chat import ( "context" + "fmt" "net/http" "net/url" @@ -39,5 +40,10 @@ func (c *Chat) UpdateUserChatColor(ctx context.Context, params *UpdateUserChatCo } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return fmt.Errorf("failed to update user chat color (%d)", res.StatusCode) + } + return nil } diff --git a/api/conduit/create_conduits.go b/api/conduit/create_conduits.go index 0e4ac07..81984cd 100644 --- a/api/conduit/create_conduits.go +++ b/api/conduit/create_conduits.go @@ -3,6 +3,7 @@ package conduit import ( "context" "encoding/json" + "fmt" "io" "net/http" "net/url" @@ -44,6 +45,11 @@ func (c *Conduit) CreateConduits(ctx context.Context, body *CreateConduitsReques } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to create conduit (%d)", res.StatusCode) + } + var data CreateConduitsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/conduit/delete_conduit.go b/api/conduit/delete_conduit.go index 512bbdd..13cb6d6 100644 --- a/api/conduit/delete_conduit.go +++ b/api/conduit/delete_conduit.go @@ -2,6 +2,7 @@ package conduit import ( "context" + "fmt" "net/http" "net/url" ) @@ -24,5 +25,10 @@ func (c *Conduit) DeleteConduit(ctx context.Context, id string) error { } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return fmt.Errorf("failed to delete conduit (%d)", res.StatusCode) + } + return nil } diff --git a/api/conduit/get_conduit_shards.go b/api/conduit/get_conduit_shards.go index 3c5205f..8163813 100644 --- a/api/conduit/get_conduit_shards.go +++ b/api/conduit/get_conduit_shards.go @@ -3,6 +3,7 @@ package conduit import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -47,6 +48,11 @@ func (c *Conduit) GetConduitShards(ctx context.Context, params *GetConduitShards } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get conduit shards (%d)", res.StatusCode) + } + var data GetConduitShardsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/conduit/get_conduits.go b/api/conduit/get_conduits.go index 64760b3..33c9655 100644 --- a/api/conduit/get_conduits.go +++ b/api/conduit/get_conduits.go @@ -3,6 +3,7 @@ package conduit import ( "context" "encoding/json" + "fmt" "net/http" "net/url" ) @@ -29,6 +30,11 @@ func (c *Conduit) GetConduits(ctx context.Context) (*GetConduitsResponse, error) } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get conduits (%d)", res.StatusCode) + } + var data GetConduitsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/conduit/update_conduit_shards.go b/api/conduit/update_conduit_shards.go index 5edb4d0..6f2dd1b 100644 --- a/api/conduit/update_conduit_shards.go +++ b/api/conduit/update_conduit_shards.go @@ -3,6 +3,7 @@ package conduit import ( "context" "encoding/json" + "fmt" "io" "net/http" "net/url" @@ -91,6 +92,11 @@ func (c *Conduit) UpdateConduitShards(ctx context.Context, body *UpdateConduitSh } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to update conduit shards (%d)", res.StatusCode) + } + var data UpdateConduitShardsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/conduit/update_conduits.go b/api/conduit/update_conduits.go index 3edb247..e851bd6 100644 --- a/api/conduit/update_conduits.go +++ b/api/conduit/update_conduits.go @@ -3,6 +3,7 @@ package conduit import ( "context" "encoding/json" + "fmt" "io" "net/http" "net/url" @@ -49,6 +50,11 @@ func (c *Conduit) UpdateConduits(ctx context.Context, body *UpdateConduitsReques } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to update conduit (%d)", res.StatusCode) + } + var data UpdateConduitsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/entitlements/get_drops_entitlements.go b/api/entitlements/get_drops_entitlements.go index b268401..1ae2c99 100644 --- a/api/entitlements/get_drops_entitlements.go +++ b/api/entitlements/get_drops_entitlements.go @@ -3,6 +3,7 @@ package entitlements import ( "context" "encoding/json" + "fmt" "net/http" "net/url" "time" @@ -101,6 +102,12 @@ func (c *Entitlements) GetDropsEntitlements(ctx context.Context, params *GetDrop if err != nil { return nil, err } + defer res.Body.Close() + + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get drops entitlements (%d)", res.StatusCode) + } var data GetDropsEntitlementsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { diff --git a/api/entitlements/update_drops_entitlements.go b/api/entitlements/update_drops_entitlements.go index 844b4dc..1a7d850 100644 --- a/api/entitlements/update_drops_entitlements.go +++ b/api/entitlements/update_drops_entitlements.go @@ -3,6 +3,7 @@ package entitlements import ( "context" "encoding/json" + "fmt" "io" "net/http" "net/url" @@ -60,6 +61,12 @@ func (c *Entitlements) UpdateDropsEntitlements(ctx context.Context, request *Upd if err != nil { return nil, err } + defer res.Body.Close() + + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to update drops entitlements (%d)", res.StatusCode) + } var data UpdateDropsEntitlementsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { diff --git a/api/eventsub/create_eventsub_subscription.go b/api/eventsub/create_eventsub_subscription.go index 8962310..7fee5a3 100644 --- a/api/eventsub/create_eventsub_subscription.go +++ b/api/eventsub/create_eventsub_subscription.go @@ -3,6 +3,7 @@ package eventsub import ( "context" "encoding/json" + "fmt" "io" "net/http" "net/url" @@ -74,6 +75,11 @@ func (e *EventSub) CreateEventSubSubscription(ctx context.Context, body *CreateE defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to create EventSub subscription (%d)", res.StatusCode) + } + var data CreateEventSubSubscriptionResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/eventsub/delete_eventsub_subscription.go b/api/eventsub/delete_eventsub_subscription.go index 0edcb48..a1e969c 100644 --- a/api/eventsub/delete_eventsub_subscription.go +++ b/api/eventsub/delete_eventsub_subscription.go @@ -2,6 +2,7 @@ package eventsub import ( "context" + "fmt" "net/http" "net/url" ) @@ -21,9 +22,16 @@ func (e *EventSub) DeleteEventSubSubscription(ctx context.Context, id string) er return err } - if _, err := e.client.Do(req); err != nil { + res, err := e.client.Do(req) + if err != nil { return err } + defer res.Body.Close() + + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return fmt.Errorf("failed to delete EventSub subscription (%d)", res.StatusCode) + } return nil } diff --git a/api/eventsub/get_eventsub_subscriptions.go b/api/eventsub/get_eventsub_subscriptions.go index 86ef9fc..f699127 100644 --- a/api/eventsub/get_eventsub_subscriptions.go +++ b/api/eventsub/get_eventsub_subscriptions.go @@ -3,6 +3,7 @@ package eventsub import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -71,6 +72,11 @@ func (e *EventSub) GetEventSubSubscriptions(ctx context.Context, params *GetEven defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get EventSub subscriptions (%d)", res.StatusCode) + } + var data GetEventSubSubscriptionsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/extensions/create_extension_secret.go b/api/extensions/create_extension_secret.go index 48d591f..5dd33db 100644 --- a/api/extensions/create_extension_secret.go +++ b/api/extensions/create_extension_secret.go @@ -3,6 +3,7 @@ package extensions import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -49,6 +50,11 @@ func (c *Extensions) CreateExtensionSecret(ctx context.Context, params *CreateEx } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to create extension secret (%d)", res.StatusCode) + } + var data CreateExtensionSecretResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/extensions/get_extension_bits_products.go b/api/extensions/get_extension_bits_products.go index 6a03d48..80f404b 100644 --- a/api/extensions/get_extension_bits_products.go +++ b/api/extensions/get_extension_bits_products.go @@ -3,6 +3,7 @@ package extensions import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -37,6 +38,11 @@ func (c *Extensions) GetExtensionBitsProducts(ctx context.Context, params *GetEx } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get extension bits products (%d)", res.StatusCode) + } + var data GetExtensionBitsProductsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/extensions/get_extension_configuration_segment.go b/api/extensions/get_extension_configuration_segment.go index aa03041..e63ebfe 100644 --- a/api/extensions/get_extension_configuration_segment.go +++ b/api/extensions/get_extension_configuration_segment.go @@ -3,6 +3,7 @@ package extensions import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -72,6 +73,11 @@ func (c *Extensions) GetExtensionConfigurationSegment(ctx context.Context, param } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get extension configuration segment (%d)", res.StatusCode) + } + var data GetExtensionConfigurationSegmentResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/extensions/get_extension_live_channels.go b/api/extensions/get_extension_live_channels.go index 08cf9ee..22e10b5 100644 --- a/api/extensions/get_extension_live_channels.go +++ b/api/extensions/get_extension_live_channels.go @@ -3,6 +3,7 @@ package extensions import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -64,6 +65,11 @@ func (c *Extensions) GetExtensionLiveChannels(ctx context.Context, params *GetEx } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get extension live channels (%d)", res.StatusCode) + } + var response GetExtensionLiveChannelsResponse if err := json.NewDecoder(res.Body).Decode(&response); err != nil { return nil, err diff --git a/api/extensions/get_extension_secrets.go b/api/extensions/get_extension_secrets.go index e757c4a..2dbdd8a 100644 --- a/api/extensions/get_extension_secrets.go +++ b/api/extensions/get_extension_secrets.go @@ -3,6 +3,7 @@ package extensions import ( "context" "encoding/json" + "fmt" "net/http" "net/url" ) @@ -33,6 +34,11 @@ func (c *Extensions) GetExtensionSecrets(ctx context.Context, extensionID string } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get extension secrets (%d)", res.StatusCode) + } + var data GetExtensionSecretsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/extensions/get_extensions.go b/api/extensions/get_extensions.go index c993d28..923e711 100644 --- a/api/extensions/get_extensions.go +++ b/api/extensions/get_extensions.go @@ -3,6 +3,7 @@ package extensions import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -45,6 +46,11 @@ func (c *Extensions) GetExtensions(ctx context.Context, params *GetExtensionsPar } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get extensions (%d)", res.StatusCode) + } + var data GetExtensionsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/extensions/get_released_extensions.go b/api/extensions/get_released_extensions.go index 3259804..c9d28ff 100644 --- a/api/extensions/get_released_extensions.go +++ b/api/extensions/get_released_extensions.go @@ -3,6 +3,7 @@ package extensions import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -40,6 +41,11 @@ func (c *Extensions) GetReleasedExtensions(ctx context.Context, params *GetRelea } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get released extensions (%d)", res.StatusCode) + } + var data GetReleasedExtensionsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/extensions/send_extension_chat_message.go b/api/extensions/send_extension_chat_message.go index acdeba5..0d6709b 100644 --- a/api/extensions/send_extension_chat_message.go +++ b/api/extensions/send_extension_chat_message.go @@ -3,6 +3,7 @@ package extensions import ( "context" "encoding/json" + "fmt" "io" "net/http" "net/url" @@ -54,5 +55,10 @@ func (c *Extensions) SendExtensionChatMessage(ctx context.Context, broadcasterID } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return fmt.Errorf("failed to send extension chat message (%d)", res.StatusCode) + } + return nil } diff --git a/api/extensions/send_extension_pubsub_message.go b/api/extensions/send_extension_pubsub_message.go index 1c4e92f..c566985 100644 --- a/api/extensions/send_extension_pubsub_message.go +++ b/api/extensions/send_extension_pubsub_message.go @@ -3,6 +3,7 @@ package extensions import ( "context" "encoding/json" + "fmt" "io" "net/http" "net/url" @@ -65,5 +66,10 @@ func (c *Extensions) SendExtensionPubsubMessage(ctx context.Context, body *SendE } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return fmt.Errorf("failed to send extension pubsub message (%d)", res.StatusCode) + } + return nil } diff --git a/api/extensions/set_extension_configuration_segment.go b/api/extensions/set_extension_configuration_segment.go index 2e1f810..39616d1 100644 --- a/api/extensions/set_extension_configuration_segment.go +++ b/api/extensions/set_extension_configuration_segment.go @@ -3,6 +3,7 @@ package extensions import ( "context" "encoding/json" + "fmt" "io" "net/http" "net/url" @@ -61,5 +62,10 @@ func (c *Extensions) SetExtensionConfigurationSegment(ctx context.Context, body } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return fmt.Errorf("failed to set extension configuration segment: %s", res.Status) + } + return nil } diff --git a/api/extensions/set_extension_required_configuration.go b/api/extensions/set_extension_required_configuration.go index 3b37994..cd74c59 100644 --- a/api/extensions/set_extension_required_configuration.go +++ b/api/extensions/set_extension_required_configuration.go @@ -3,6 +3,7 @@ package extensions import ( "context" "encoding/json" + "fmt" "io" "net/http" "net/url" @@ -55,5 +56,10 @@ func (c *Extensions) SetExtensionRequiredConfiguration(ctx context.Context, broa } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return fmt.Errorf("failed to set extension required configuration (%d)", res.StatusCode) + } + return nil } diff --git a/api/extensions/update_extension_bits_product.go b/api/extensions/update_extension_bits_product.go index e4a5c34..2c51f75 100644 --- a/api/extensions/update_extension_bits_product.go +++ b/api/extensions/update_extension_bits_product.go @@ -3,6 +3,7 @@ package extensions import ( "context" "encoding/json" + "fmt" "io" "net/http" "net/url" @@ -75,6 +76,11 @@ func (c *Extensions) UpdateExtensionBitsProduct(ctx context.Context, body *Updat } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to update extension bits product (%d)", res.StatusCode) + } + var data UpdateExtensionBitsProductResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/games/get_games.go b/api/games/get_games.go index 55c7a60..ce94fae 100644 --- a/api/games/get_games.go +++ b/api/games/get_games.go @@ -3,6 +3,7 @@ package games import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -49,6 +50,11 @@ func (c *Games) GetGames(ctx context.Context, params *GetGamesParams) (*GetGames } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get games (%d)", res.StatusCode) + } + var data GetGamesResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/games/get_top_games.go b/api/games/get_top_games.go index c9750cf..0a860b9 100644 --- a/api/games/get_top_games.go +++ b/api/games/get_top_games.go @@ -3,6 +3,7 @@ package games import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -52,6 +53,11 @@ func (c *Games) GetTopGames(ctx context.Context, params *GetTopGamesParams) (*Ge } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get top games (%d)", res.StatusCode) + } + var data GetTopGamesResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/goals/get_creator_goals.go b/api/goals/get_creator_goals.go index bb6a7d9..a4b08df 100644 --- a/api/goals/get_creator_goals.go +++ b/api/goals/get_creator_goals.go @@ -3,6 +3,7 @@ package goals import ( "context" "encoding/json" + "fmt" "net/http" "net/url" "time" @@ -95,6 +96,11 @@ func (c *Goals) GetCreatorGoals(ctx context.Context, broadcasterID string) (*Get } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get creator goals (%d)", res.StatusCode) + } + var data GetCreatorGoalsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/gueststar/assign_gueststar_slot.go b/api/gueststar/assign_gueststar_slot.go index 1a6bffd..6e14156 100644 --- a/api/gueststar/assign_gueststar_slot.go +++ b/api/gueststar/assign_gueststar_slot.go @@ -2,6 +2,7 @@ package gueststar import ( "context" + "fmt" "net/http" "net/url" @@ -47,5 +48,10 @@ func (g *GuestStar) AssignGuestStarSlot(ctx context.Context, params *AssignGuest } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return fmt.Errorf("failed to assign guest star slot (%d)", res.StatusCode) + } + return nil } diff --git a/api/gueststar/create_gueststar_session.go b/api/gueststar/create_gueststar_session.go index 635f2cb..5e042f0 100644 --- a/api/gueststar/create_gueststar_session.go +++ b/api/gueststar/create_gueststar_session.go @@ -3,6 +3,7 @@ package gueststar import ( "context" "encoding/json" + "fmt" "net/http" "net/url" ) @@ -30,6 +31,11 @@ func (g *GuestStar) CreateGuestStarSession(ctx context.Context, broadcasterID st } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to create guest star session (%d)", res.StatusCode) + } + var data CreateGuestStarSessionResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/gueststar/delete_gueststar_invite.go b/api/gueststar/delete_gueststar_invite.go index fda6a33..e646c75 100644 --- a/api/gueststar/delete_gueststar_invite.go +++ b/api/gueststar/delete_gueststar_invite.go @@ -2,6 +2,7 @@ package gueststar import ( "context" + "fmt" "net/http" "net/url" @@ -42,5 +43,10 @@ func (g *GuestStar) DeleteGuestStarInvite(ctx context.Context, params *DeleteGue } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return fmt.Errorf("failed to delete guest star invite (%d)", res.StatusCode) + } + return nil } diff --git a/api/gueststar/delete_gueststar_slot.go b/api/gueststar/delete_gueststar_slot.go index 191e836..82f8f1a 100644 --- a/api/gueststar/delete_gueststar_slot.go +++ b/api/gueststar/delete_gueststar_slot.go @@ -2,6 +2,7 @@ package gueststar import ( "context" + "fmt" "net/http" "net/url" @@ -49,5 +50,10 @@ func (g *GuestStar) DeleteGuestStarSlot(ctx context.Context, params *DeleteGuest } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return fmt.Errorf("failed to delete guest star slot (%d)", res.StatusCode) + } + return nil } diff --git a/api/gueststar/end_gueststar_session.go b/api/gueststar/end_gueststar_session.go index 994c7e7..a3d0a8b 100644 --- a/api/gueststar/end_gueststar_session.go +++ b/api/gueststar/end_gueststar_session.go @@ -3,6 +3,7 @@ package gueststar import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -42,6 +43,11 @@ func (g *GuestStar) EndGuestStarSession(ctx context.Context, params *EndGuestSta } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to end guest star session (%d)", res.StatusCode) + } + var data EndGuestStarSessionResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/gueststar/get_channel_gueststar_settings.go b/api/gueststar/get_channel_gueststar_settings.go index 57b22a4..eacd17d 100644 --- a/api/gueststar/get_channel_gueststar_settings.go +++ b/api/gueststar/get_channel_gueststar_settings.go @@ -3,6 +3,7 @@ package gueststar import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -41,6 +42,11 @@ func (g *GuestStar) GetChannelGuestStarSettings(ctx context.Context, params *Get } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get channel guest star settings (%d)", res.StatusCode) + } + var data GetChannelGuestStarSettingsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/gueststar/get_gueststar_invites.go b/api/gueststar/get_gueststar_invites.go index 9b80761..2375608 100644 --- a/api/gueststar/get_gueststar_invites.go +++ b/api/gueststar/get_gueststar_invites.go @@ -3,6 +3,7 @@ package gueststar import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -45,6 +46,11 @@ func (g *GuestStar) GetGuestStarInvites(ctx context.Context, params *GetGuestSta } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get guest star invites (%d)", res.StatusCode) + } + var data GetGuestStarInvitesResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/gueststar/get_gueststar_session.go b/api/gueststar/get_gueststar_session.go index 99a07ec..7b70ab0 100644 --- a/api/gueststar/get_gueststar_session.go +++ b/api/gueststar/get_gueststar_session.go @@ -3,6 +3,7 @@ package gueststar import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -42,6 +43,11 @@ func (g *GuestStar) GetGuestStarSession(ctx context.Context, params *GetGuestSta } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get guest star session (%d)", res.StatusCode) + } + var data GetGuestStarSessionResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/gueststar/send_gueststar_invite.go b/api/gueststar/send_gueststar_invite.go index 2bced5d..ec09867 100644 --- a/api/gueststar/send_gueststar_invite.go +++ b/api/gueststar/send_gueststar_invite.go @@ -2,6 +2,7 @@ package gueststar import ( "context" + "fmt" "net/http" "net/url" @@ -42,5 +43,10 @@ func (g *GuestStar) SendGuestStarInvite(ctx context.Context, params *SendGuestSt } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return fmt.Errorf("failed to send guest star invite (%d)", res.StatusCode) + } + return nil } diff --git a/api/gueststar/update_channel_gueststar_settings.go b/api/gueststar/update_channel_gueststar_settings.go index 77a4cf4..53c28aa 100644 --- a/api/gueststar/update_channel_gueststar_settings.go +++ b/api/gueststar/update_channel_gueststar_settings.go @@ -2,6 +2,7 @@ package gueststar import ( "context" + "fmt" "net/http" "net/url" ) @@ -51,5 +52,10 @@ func (g *GuestStar) UpdateChannelGuestStarSettings(ctx context.Context, Broadcas } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return fmt.Errorf("failed to update channel guest star settings (%d)", res.StatusCode) + } + return nil } diff --git a/api/gueststar/update_gueststar_slot.go b/api/gueststar/update_gueststar_slot.go index 3d69232..46228e1 100644 --- a/api/gueststar/update_gueststar_slot.go +++ b/api/gueststar/update_gueststar_slot.go @@ -2,6 +2,7 @@ package gueststar import ( "context" + "fmt" "net/http" "net/url" @@ -45,5 +46,10 @@ func (g *GuestStar) UpdateGuestStarSlot(ctx context.Context, params *UpdateGuest } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return fmt.Errorf("failed to update guest star slot (%d)", res.StatusCode) + } + return nil } diff --git a/api/gueststar/update_gueststar_slot_settings.go b/api/gueststar/update_gueststar_slot_settings.go index a93eafa..b5ba135 100644 --- a/api/gueststar/update_gueststar_slot_settings.go +++ b/api/gueststar/update_gueststar_slot_settings.go @@ -2,6 +2,7 @@ package gueststar import ( "context" + "fmt" "net/http" "net/url" @@ -57,5 +58,10 @@ func (g *GuestStar) UpdateGuestStarSlotSettings(ctx context.Context, params *Upd } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return fmt.Errorf("failed to update guest star slot settings (%d)", res.StatusCode) + } + return nil } diff --git a/api/hypetrain/get_hypetrain_events.go b/api/hypetrain/get_hypetrain_events.go index 1664787..d65f70a 100644 --- a/api/hypetrain/get_hypetrain_events.go +++ b/api/hypetrain/get_hypetrain_events.go @@ -3,6 +3,7 @@ package hypetrain import ( "context" "encoding/json" + "fmt" "net/http" "net/url" "time" @@ -131,6 +132,11 @@ func (h *Hypetrain) GetHypeTrainEvents(ctx context.Context, params *GetHypeTrain } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get Hype Train events (%d)", res.StatusCode) + } + var data GetHypeTrainEventsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/moderation/add_blocked_term.go b/api/moderation/add_blocked_term.go index 38627d2..b78d686 100644 --- a/api/moderation/add_blocked_term.go +++ b/api/moderation/add_blocked_term.go @@ -3,6 +3,7 @@ package moderation import ( "context" "encoding/json" + "fmt" "io" "net/http" "net/url" @@ -65,6 +66,11 @@ func (m *Moderation) AddBlockedTerm(ctx context.Context, params *AddBlockedTermP } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to add blocked term (%d)", res.StatusCode) + } + var data AddBlockedTermResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/moderation/add_channel_moderator.go b/api/moderation/add_channel_moderator.go index f517afd..b3ce228 100644 --- a/api/moderation/add_channel_moderator.go +++ b/api/moderation/add_channel_moderator.go @@ -2,6 +2,7 @@ package moderation import ( "context" + "fmt" "net/http" "net/url" @@ -36,5 +37,10 @@ func (m *Moderation) AddChannelModerator(ctx context.Context, params *AddChannel } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return fmt.Errorf("failed to add channel moderator (%d)", res.StatusCode) + } + return nil } diff --git a/api/moderation/add_channel_vip.go b/api/moderation/add_channel_vip.go index c88a14e..a79a67b 100644 --- a/api/moderation/add_channel_vip.go +++ b/api/moderation/add_channel_vip.go @@ -2,6 +2,7 @@ package moderation import ( "context" + "fmt" "net/http" "net/url" @@ -36,5 +37,10 @@ func (m *Moderation) AddChannelVIP(ctx context.Context, params *AddChannelVIPPar } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return fmt.Errorf("failed to add channel VIP (%d)", res.StatusCode) + } + return nil } diff --git a/api/moderation/ban_user.go b/api/moderation/ban_user.go index 21619ed..23c459b 100644 --- a/api/moderation/ban_user.go +++ b/api/moderation/ban_user.go @@ -3,6 +3,7 @@ package moderation import ( "context" "encoding/json" + "fmt" "io" "net/http" "net/url" @@ -92,6 +93,11 @@ func (m *Moderation) BanUser(ctx context.Context, params *BanUserParams, body *B } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to ban user (%d)", res.StatusCode) + } + var data BanUserResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/moderation/check_automod_status.go b/api/moderation/check_automod_status.go index 2ff127c..ca93bb3 100644 --- a/api/moderation/check_automod_status.go +++ b/api/moderation/check_automod_status.go @@ -3,6 +3,7 @@ package moderation import ( "context" "encoding/json" + "fmt" "net/http" "net/url" ) @@ -64,6 +65,11 @@ func (c *Moderation) CheckAutoModStatus(ctx context.Context, broadcasterID strin } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to check automod status (%d)", res.StatusCode) + } + var data CheckAutoModStatusResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/moderation/delete_chat_messages.go b/api/moderation/delete_chat_messages.go index 3a1f565..1446ed0 100644 --- a/api/moderation/delete_chat_messages.go +++ b/api/moderation/delete_chat_messages.go @@ -2,6 +2,7 @@ package moderation import ( "context" + "fmt" "net/http" "net/url" @@ -46,5 +47,10 @@ func (m *Moderation) DeleteChatMessages(ctx context.Context, params *DeleteChatM } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return fmt.Errorf("failed to delete chat messages (%d)", res.StatusCode) + } + return nil } diff --git a/api/moderation/get_automod_settings.go b/api/moderation/get_automod_settings.go index 4758597..c8a2d27 100644 --- a/api/moderation/get_automod_settings.go +++ b/api/moderation/get_automod_settings.go @@ -3,6 +3,7 @@ package moderation import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -42,6 +43,11 @@ func (m *Moderation) GetAutoModSettings(ctx context.Context, params *GetAutoModS } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get automod settings (%d)", res.StatusCode) + } + var data GetAutoModSettingsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/moderation/get_banned_users.go b/api/moderation/get_banned_users.go index 363b726..3a8cd97 100644 --- a/api/moderation/get_banned_users.go +++ b/api/moderation/get_banned_users.go @@ -3,6 +3,7 @@ package moderation import ( "context" "encoding/json" + "fmt" "net/http" "net/url" "time" @@ -95,6 +96,11 @@ func (m *Moderation) GetBannedUsers(ctx context.Context, params *GetBannedUsersP } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get banned users (%d)", res.StatusCode) + } + var data GetBannedUsersResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/moderation/get_blocked_terms.go b/api/moderation/get_blocked_terms.go index bfdeb22..96ecbc9 100644 --- a/api/moderation/get_blocked_terms.go +++ b/api/moderation/get_blocked_terms.go @@ -3,6 +3,7 @@ package moderation import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -56,6 +57,11 @@ func (m *Moderation) GetBlockedTerms(ctx context.Context, params *GetBlockedTerm } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get blocked terms (%d)", res.StatusCode) + } + var data GetBlockedTermsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/moderation/get_moderated_channels.go b/api/moderation/get_moderated_channels.go index 93c4d67..db8a2a6 100644 --- a/api/moderation/get_moderated_channels.go +++ b/api/moderation/get_moderated_channels.go @@ -3,6 +3,7 @@ package moderation import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -63,6 +64,11 @@ func (m *Moderation) GetModeratedChannels(ctx context.Context, params *GetModera } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get moderated channels (%d)", res.StatusCode) + } + var data GetModeratedChannelsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/moderation/get_moderators.go b/api/moderation/get_moderators.go index fd693bd..28865ed 100644 --- a/api/moderation/get_moderators.go +++ b/api/moderation/get_moderators.go @@ -3,6 +3,7 @@ package moderation import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -73,6 +74,11 @@ func (m *Moderation) GetModerators(ctx context.Context, params *GetModeratorsPar } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get moderators (%d)", res.StatusCode) + } + var data GetModeratorsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/moderation/get_shield_mode_status.go b/api/moderation/get_shield_mode_status.go index faafd8e..bfc5008 100644 --- a/api/moderation/get_shield_mode_status.go +++ b/api/moderation/get_shield_mode_status.go @@ -3,6 +3,7 @@ package moderation import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -43,6 +44,11 @@ func (m *Moderation) GetShieldModeStatus(ctx context.Context, params *GetShieldM } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get shield mode status (%d)", res.StatusCode) + } + var data GetShieldModeStatusResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/moderation/get_vips.go b/api/moderation/get_vips.go index 4537477..3a3c122 100644 --- a/api/moderation/get_vips.go +++ b/api/moderation/get_vips.go @@ -3,6 +3,7 @@ package moderation import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -69,6 +70,12 @@ func (m *Moderation) GetVIPs(ctx context.Context, params GetVIPsParams) (*GetVIP if err != nil { return nil, err } + defer res.Body.Close() + + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get VIPs (%d)", res.StatusCode) + } var data GetVIPsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { diff --git a/api/moderation/manage_held_automod_messages.go b/api/moderation/manage_held_automod_messages.go index 9b3e37a..76b1e72 100644 --- a/api/moderation/manage_held_automod_messages.go +++ b/api/moderation/manage_held_automod_messages.go @@ -2,6 +2,7 @@ package moderation import ( "context" + "fmt" "net/http" "net/url" ) @@ -45,5 +46,10 @@ func (m *Moderation) ManageHeldAutoModMessages(ctx context.Context, body *Manage } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return fmt.Errorf("failed to manage held AutoMod messages (%d)", res.StatusCode) + } + return nil } diff --git a/api/moderation/remove_blocked_term.go b/api/moderation/remove_blocked_term.go index ef0240c..900982d 100644 --- a/api/moderation/remove_blocked_term.go +++ b/api/moderation/remove_blocked_term.go @@ -2,6 +2,7 @@ package moderation import ( "context" + "fmt" "net/http" "net/url" @@ -38,5 +39,10 @@ func (m *Moderation) RemoveBlockedTerm(ctx context.Context, params *RemoveBlocke } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return fmt.Errorf("failed to remove blocked term (%d)", res.StatusCode) + } + return nil } diff --git a/api/moderation/remove_channel_moderator.go b/api/moderation/remove_channel_moderator.go index 36de55b..b976f6e 100644 --- a/api/moderation/remove_channel_moderator.go +++ b/api/moderation/remove_channel_moderator.go @@ -2,6 +2,7 @@ package moderation import ( "context" + "fmt" "net/http" "net/url" @@ -36,5 +37,10 @@ func (m *Moderation) RemoveChannelModerator(ctx context.Context, params *RemoveC } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return fmt.Errorf("failed to remove channel moderator (%d)", res.StatusCode) + } + return nil } diff --git a/api/moderation/remove_channel_vip.go b/api/moderation/remove_channel_vip.go index 9cbc3ed..5e678f7 100644 --- a/api/moderation/remove_channel_vip.go +++ b/api/moderation/remove_channel_vip.go @@ -2,6 +2,7 @@ package moderation import ( "context" + "fmt" "net/http" "net/url" @@ -39,5 +40,10 @@ func (m *Moderation) RemoveChannelVIP(ctx context.Context, params *RemoveChannel } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return fmt.Errorf("failed to remove channel VIP (%d)", res.StatusCode) + } + return nil } diff --git a/api/moderation/unban_user.go b/api/moderation/unban_user.go index a738ecd..9512b4e 100644 --- a/api/moderation/unban_user.go +++ b/api/moderation/unban_user.go @@ -2,6 +2,7 @@ package moderation import ( "context" + "fmt" "net/http" "net/url" @@ -40,5 +41,10 @@ func (m *Moderation) UnbanUser(ctx context.Context, params *UnbanUserParams) err } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return fmt.Errorf("failed to unban user (%d)", res.StatusCode) + } + return nil } diff --git a/api/moderation/update_automod_settings.go b/api/moderation/update_automod_settings.go index 0a88888..9bde0c5 100644 --- a/api/moderation/update_automod_settings.go +++ b/api/moderation/update_automod_settings.go @@ -3,6 +3,7 @@ package moderation import ( "context" "encoding/json" + "fmt" "io" "net/http" "net/url" @@ -101,6 +102,11 @@ func (m *Moderation) UpdateAutoModSettings(ctx context.Context, params *UpdateAu } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to update automod settings (%d)", res.StatusCode) + } + var data UpdateAutoModSettingsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/moderation/update_shield_mode_status.go b/api/moderation/update_shield_mode_status.go index bb44704..38c2632 100644 --- a/api/moderation/update_shield_mode_status.go +++ b/api/moderation/update_shield_mode_status.go @@ -3,6 +3,7 @@ package moderation import ( "context" "encoding/json" + "fmt" "io" "net/http" "net/url" @@ -60,6 +61,11 @@ func (m *Moderation) UpdateShieldModeStatus(ctx context.Context, params *UpdateS } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to update shield mode status (%d)", res.StatusCode) + } + var data UpdateShieldModeStatusResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/polls/create_poll.go b/api/polls/create_poll.go index 00f1337..c005aaf 100644 --- a/api/polls/create_poll.go +++ b/api/polls/create_poll.go @@ -3,6 +3,7 @@ package polls import ( "context" "encoding/json" + "fmt" "io" "net/http" "net/url" @@ -71,6 +72,11 @@ func (p *Polls) CreatePoll(ctx context.Context, body *CreatePollRequest) (*Creat } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to create poll (%d)", res.StatusCode) + } + var data CreatePollResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/polls/end_poll.go b/api/polls/end_poll.go index f6b7c4d..dfacfeb 100644 --- a/api/polls/end_poll.go +++ b/api/polls/end_poll.go @@ -2,6 +2,7 @@ package polls import ( "context" + "fmt" "net/http" "net/url" @@ -42,5 +43,10 @@ func (p *Polls) EndPoll(ctx context.Context, params *EndPollParams) error { } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return fmt.Errorf("failed to end poll (%d)", res.StatusCode) + } + return nil } diff --git a/api/polls/get_polls.go b/api/polls/get_polls.go index 8fbdb60..b99abf0 100644 --- a/api/polls/get_polls.go +++ b/api/polls/get_polls.go @@ -3,6 +3,7 @@ package polls import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -62,6 +63,11 @@ func (p *Polls) GetPolls(ctx context.Context, params *GetPollsParams) (*GetPolls } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get polls (%d)", res.StatusCode) + } + var data GetPollsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/predictions/create_prediction.go b/api/predictions/create_prediction.go index 19175de..94faacd 100644 --- a/api/predictions/create_prediction.go +++ b/api/predictions/create_prediction.go @@ -3,6 +3,7 @@ package predictions import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -54,6 +55,11 @@ func (c *Predictions) CreatePrediction(ctx context.Context, params *CreatePredic } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to create prediction (%d)", res.StatusCode) + } + var data CreatePredictionResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/predictions/end_prediction.go b/api/predictions/end_prediction.go index c9119a3..382507d 100644 --- a/api/predictions/end_prediction.go +++ b/api/predictions/end_prediction.go @@ -3,6 +3,7 @@ package predictions import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -57,6 +58,11 @@ func (c *Predictions) EndPrediction(ctx context.Context, params *EndPredictionRe } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to end prediction (%d)", res.StatusCode) + } + var data EndPredictionResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/predictions/get_predictions.go b/api/predictions/get_predictions.go index 7a69f33..e087cbb 100644 --- a/api/predictions/get_predictions.go +++ b/api/predictions/get_predictions.go @@ -3,6 +3,7 @@ package predictions import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -60,6 +61,11 @@ func (c *Predictions) GetPredictions(ctx context.Context, params *GetPredictions } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get predictions (%d)", res.StatusCode) + } + var data GetPredictionsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/raids/cancel_a_raid.go b/api/raids/cancel_a_raid.go index 9ffff5b..074f4c3 100644 --- a/api/raids/cancel_a_raid.go +++ b/api/raids/cancel_a_raid.go @@ -2,6 +2,7 @@ package raids import ( "context" + "fmt" "net/http" "net/url" ) @@ -29,5 +30,10 @@ func (c *Raids) CancelARaid(ctx context.Context, broadcasterID string) error { } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return fmt.Errorf("failed to cancel a raid (%d)", res.StatusCode) + } + return nil } diff --git a/api/raids/start_a_raid.go b/api/raids/start_a_raid.go index 88b4915..85a52bd 100644 --- a/api/raids/start_a_raid.go +++ b/api/raids/start_a_raid.go @@ -3,6 +3,7 @@ package raids import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -56,6 +57,11 @@ func (c *Raids) StartARaid(ctx context.Context, params *StartARaidParams) (*Star } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to start a raid (%d)", res.StatusCode) + } + var data StartARaidResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/schedule/create_channel_stream_schedule_segment.go b/api/schedule/create_channel_stream_schedule_segment.go index 9b243a2..ac3d317 100644 --- a/api/schedule/create_channel_stream_schedule_segment.go +++ b/api/schedule/create_channel_stream_schedule_segment.go @@ -3,6 +3,7 @@ package schedule import ( "context" "encoding/json" + "fmt" "io" "net/http" "net/url" @@ -65,6 +66,11 @@ func (s *Schedule) CreateChannelStreamScheduleSegment(ctx context.Context, broad } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to create channel stream schedule segment (%d)", res.StatusCode) + } + var data CreateChannelStreamScheduleSegmentResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/schedule/delete_channel_stream_schedule_segment.go b/api/schedule/delete_channel_stream_schedule_segment.go index 7ca3851..60e018d 100644 --- a/api/schedule/delete_channel_stream_schedule_segment.go +++ b/api/schedule/delete_channel_stream_schedule_segment.go @@ -2,6 +2,7 @@ package schedule import ( "context" + "fmt" "net/http" "net/url" @@ -36,5 +37,10 @@ func (s *Schedule) DeleteChannelStreamScheduleSegment(ctx context.Context, param } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return fmt.Errorf("failed to delete channel stream schedule segment (%d)", res.StatusCode) + } + return nil } diff --git a/api/schedule/get_channel_stream_schedule.go b/api/schedule/get_channel_stream_schedule.go index 1f6f189..66e8f93 100644 --- a/api/schedule/get_channel_stream_schedule.go +++ b/api/schedule/get_channel_stream_schedule.go @@ -3,6 +3,7 @@ package schedule import ( "context" "encoding/json" + "fmt" "net/http" "net/url" "time" @@ -63,6 +64,11 @@ func (s *Schedule) GetChannelStreamSchedule(ctx context.Context, params *GetChan } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get channel stream schedule (%d)", res.StatusCode) + } + var data GetChannelStreamScheduleResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/schedule/update_channel_stream_schedule.go b/api/schedule/update_channel_stream_schedule.go index ce86a54..5a0df27 100644 --- a/api/schedule/update_channel_stream_schedule.go +++ b/api/schedule/update_channel_stream_schedule.go @@ -2,6 +2,7 @@ package schedule import ( "context" + "fmt" "net/http" "net/url" "time" @@ -49,5 +50,10 @@ func (s *Schedule) UpdateChannelStreamSchedule(ctx context.Context, params *Upda } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return fmt.Errorf("failed to update channel stream schedule (%d)", res.StatusCode) + } + return nil } diff --git a/api/schedule/update_channel_stream_schedule_segment.go b/api/schedule/update_channel_stream_schedule_segment.go index b90c32f..d220375 100644 --- a/api/schedule/update_channel_stream_schedule_segment.go +++ b/api/schedule/update_channel_stream_schedule_segment.go @@ -3,6 +3,7 @@ package schedule import ( "context" "encoding/json" + "fmt" "io" "net/http" "net/url" @@ -81,6 +82,11 @@ func (s *Schedule) UpdateChannelStreamScheduleSegment(ctx context.Context, param } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to update channel stream schedule segment (%d)", res.StatusCode) + } + var data UpdateChannelStreamScheduleSegmentResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/search/search_categories.go b/api/search/search_categories.go index 8b16598..e8f3e12 100644 --- a/api/search/search_categories.go +++ b/api/search/search_categories.go @@ -3,6 +3,7 @@ package search import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -65,6 +66,11 @@ func (c *Search) SearchCategories(ctx context.Context, params *SearchCategoriesP } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("search categories request failed: %s", res.Status) + } + var data SearchCategoriesResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/search/search_channels.go b/api/search/search_channels.go index d0dea8d..1815f6f 100644 --- a/api/search/search_channels.go +++ b/api/search/search_channels.go @@ -3,6 +3,7 @@ package search import ( "context" "encoding/json" + "fmt" "net/http" "net/url" "time" @@ -99,6 +100,11 @@ func (c *Search) SearchChannels(ctx context.Context, params *SearchChannelsParam } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to search channels (%d)", res.StatusCode) + } + var data SearchChannelsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/streams/create_stream_marker.go b/api/streams/create_stream_marker.go index ef83739..1cf8e44 100644 --- a/api/streams/create_stream_marker.go +++ b/api/streams/create_stream_marker.go @@ -3,6 +3,7 @@ package streams import ( "context" "encoding/json" + "fmt" "io" "net/http" "net/url" @@ -61,6 +62,11 @@ func (s *Streams) CreateStreamMarker(ctx context.Context, body *CreateStreamMark } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to create stream marker (%d)", res.StatusCode) + } + var data CreateStreamMarkerResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/streams/get_followed_streams.go b/api/streams/get_followed_streams.go index 8a820c2..b98563d 100644 --- a/api/streams/get_followed_streams.go +++ b/api/streams/get_followed_streams.go @@ -3,6 +3,7 @@ package streams import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -56,6 +57,11 @@ func (s *Streams) GetFollowedStreams(ctx context.Context, params *GetFollowedStr } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get followed streams (%d)", res.StatusCode) + } + var data GetFollowedStreamsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/streams/get_stream_key.go b/api/streams/get_stream_key.go index f296106..5c69c3c 100644 --- a/api/streams/get_stream_key.go +++ b/api/streams/get_stream_key.go @@ -3,6 +3,7 @@ package streams import ( "context" "encoding/json" + "fmt" "net/http" "net/url" ) @@ -34,6 +35,11 @@ func (s *Streams) GetStreamKey(ctx context.Context, broadcasterID string) (*GetS } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get stream key (%d)", res.StatusCode) + } + var data GetStreamKeyResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/streams/get_stream_markers.go b/api/streams/get_stream_markers.go index 4d93cef..9dc6135 100644 --- a/api/streams/get_stream_markers.go +++ b/api/streams/get_stream_markers.go @@ -3,6 +3,7 @@ package streams import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -69,6 +70,11 @@ func (s *Streams) GetStreamMarkers(ctx context.Context, params *GetStreamMarkers } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get stream markers (%d)", res.StatusCode) + } + var data GetStreamMarkersResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/streams/get_streams.go b/api/streams/get_streams.go index c87b8f8..6f3b2d1 100644 --- a/api/streams/get_streams.go +++ b/api/streams/get_streams.go @@ -3,6 +3,7 @@ package streams import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -90,6 +91,11 @@ func (s *Streams) GetStreams(ctx context.Context, params *GetStreamsParams) (*Ge } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get streams (%d)", res.StatusCode) + } + var data GetStreamsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/subscriptions/check_user_subscription.go b/api/subscriptions/check_user_subscription.go index 999911c..3e62954 100644 --- a/api/subscriptions/check_user_subscription.go +++ b/api/subscriptions/check_user_subscription.go @@ -3,6 +3,7 @@ package subscriptions import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -75,6 +76,11 @@ func (s *Subscriptions) CheckUserSubscription(ctx context.Context, params *Check } defer resp.Body.Close() + statusOK := resp.StatusCode >= 200 && resp.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to check user subscription (%d)", resp.StatusCode) + } + var data CheckUserSubscriptionResponse if err := json.NewDecoder(resp.Body).Decode(&data); err != nil { return nil, err diff --git a/api/subscriptions/get_broadcaster_subscriptions.go b/api/subscriptions/get_broadcaster_subscriptions.go index 748f2cd..ce6f668 100644 --- a/api/subscriptions/get_broadcaster_subscriptions.go +++ b/api/subscriptions/get_broadcaster_subscriptions.go @@ -3,6 +3,7 @@ package subscriptions import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -118,6 +119,11 @@ func (c *Subscriptions) GetBroadcasterSubscriptions(ctx context.Context, params } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get broadcaster subscriptions (%d)", res.StatusCode) + } + var data GetBroadcasterSubscriptionsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/teams/get_channel_teams.go b/api/teams/get_channel_teams.go index 928c5bd..20b4430 100644 --- a/api/teams/get_channel_teams.go +++ b/api/teams/get_channel_teams.go @@ -3,6 +3,7 @@ package teams import ( "context" "encoding/json" + "fmt" "net/http" "net/url" "time" @@ -69,6 +70,11 @@ func (c *Teams) GetChannelTeams(ctx context.Context, broadcasterID string) (*Get } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get channel teams (%d)", res.StatusCode) + } + var data GetChannelTeamsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/teams/get_teams.go b/api/teams/get_teams.go index a25951e..931210e 100644 --- a/api/teams/get_teams.go +++ b/api/teams/get_teams.go @@ -3,6 +3,7 @@ package teams import ( "context" "encoding/json" + "fmt" "net/http" "net/url" "time" @@ -82,6 +83,11 @@ func (c *Teams) GetTeams(ctx context.Context, params *GetTeamsParams) (*GetTeams } defer resp.Body.Close() + statusOK := resp.StatusCode >= 200 && resp.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get teams (%d)", resp.StatusCode) + } + var data GetTeamsResponse if err := json.NewDecoder(resp.Body).Decode(&data); err != nil { return nil, err diff --git a/api/users/block_user.go b/api/users/block_user.go index 0795ae6..9889a3c 100644 --- a/api/users/block_user.go +++ b/api/users/block_user.go @@ -2,6 +2,7 @@ package users import ( "context" + "fmt" "net/http" "net/url" @@ -45,5 +46,10 @@ func (u *Users) BlockUser(ctx context.Context, params *BlockUserParams) error { } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return fmt.Errorf("failed to block user (%d)", res.StatusCode) + } + return nil } diff --git a/api/users/get_user_active_extensions.go b/api/users/get_user_active_extensions.go index a16ad9d..453d7d3 100644 --- a/api/users/get_user_active_extensions.go +++ b/api/users/get_user_active_extensions.go @@ -3,6 +3,7 @@ package users import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -43,6 +44,11 @@ func (u *Users) GetUserActiveExtensions(ctx context.Context, params *GetUserActi } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get user active extensions (%d)", res.StatusCode) + } + var data GetUserActiveExtensionsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/users/get_user_block_list.go b/api/users/get_user_block_list.go index 863e0b2..6ad62c7 100644 --- a/api/users/get_user_block_list.go +++ b/api/users/get_user_block_list.go @@ -3,6 +3,7 @@ package users import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -58,6 +59,11 @@ func (u *Users) GetUserBlockList(ctx context.Context, params *GetUserBlockListPa } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get user block list (%d)", res.StatusCode) + } + var data GetUserBlockListResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/users/get_user_extensions.go b/api/users/get_user_extensions.go index 1db7f38..5dde947 100644 --- a/api/users/get_user_extensions.go +++ b/api/users/get_user_extensions.go @@ -3,6 +3,7 @@ package users import ( "context" "encoding/json" + "fmt" "net/http" "net/url" ) @@ -48,6 +49,11 @@ func (u *Users) GetUserExtensions(ctx context.Context) (*GetUserExtensionsRespon } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get user extensions (%d)", res.StatusCode) + } + var data GetUserExtensionsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/users/get_users.go b/api/users/get_users.go index 6e2de49..1b768fc 100644 --- a/api/users/get_users.go +++ b/api/users/get_users.go @@ -3,8 +3,7 @@ package users import ( "context" "encoding/json" - "io" - "log/slog" + "fmt" "net/http" "net/url" @@ -53,14 +52,13 @@ func (u *Users) GetUsers(ctx context.Context, params *GetUsersParams) (*GetUsers } defer res.Body.Close() - body, err := io.ReadAll(res.Body) - if err != nil { - return nil, err + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get users (%d)", res.StatusCode) } var data GetUsersResponse - if err := json.Unmarshal(body, &data); err != nil { - slog.Debug("failed to unmarshal", "error", err, "body", string(body)) + if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err } diff --git a/api/users/unblock_user.go b/api/users/unblock_user.go index 0067fda..86d57b7 100644 --- a/api/users/unblock_user.go +++ b/api/users/unblock_user.go @@ -2,6 +2,7 @@ package users import ( "context" + "fmt" "net/http" "net/url" ) @@ -24,5 +25,10 @@ func (u *Users) UnblockUser(ctx context.Context, targetUserID string) error { } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return fmt.Errorf("failed to unblock user (%d)", res.StatusCode) + } + return nil } diff --git a/api/users/update_user.go b/api/users/update_user.go index af8c9a9..3fa64cd 100644 --- a/api/users/update_user.go +++ b/api/users/update_user.go @@ -3,6 +3,7 @@ package users import ( "context" "encoding/json" + "fmt" "net/http" "net/url" @@ -41,6 +42,11 @@ func (u *Users) UpdateUser(ctx context.Context, params *UpdateUserParams) (*Upda } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to update user (%d)", res.StatusCode) + } + var data UpdateUserResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/users/update_user_extensions.go b/api/users/update_user_extensions.go index fd5325c..c64b199 100644 --- a/api/users/update_user_extensions.go +++ b/api/users/update_user_extensions.go @@ -3,6 +3,7 @@ package users import ( "context" "encoding/json" + "fmt" "io" "net/http" "net/url" @@ -57,6 +58,11 @@ func (u *Users) UpdateUserExtensions(ctx context.Context, body *UpdateUserExtens } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to update user extensions (%d)", res.StatusCode) + } + var data UpdateUserExtensionsResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/videos/delete_videos.go b/api/videos/delete_videos.go index c5599c5..a7f3c3a 100644 --- a/api/videos/delete_videos.go +++ b/api/videos/delete_videos.go @@ -3,6 +3,7 @@ package videos import ( "context" "encoding/json" + "fmt" "net/http" "net/url" ) @@ -29,6 +30,11 @@ func (v *Videos) DeleteVideos(ctx context.Context, ids []string) (*DeleteVideosR } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to delete videos (%d)", res.StatusCode) + } + var data DeleteVideosResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/videos/get_videos.go b/api/videos/get_videos.go index b6c8903..83b906b 100644 --- a/api/videos/get_videos.go +++ b/api/videos/get_videos.go @@ -3,6 +3,7 @@ package videos import ( "context" "encoding/json" + "fmt" "net/http" "net/url" "time" @@ -198,6 +199,11 @@ func (vid *Videos) GetVideos(ctx context.Context, params *GetVideosParams) (*Get } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get videos (%d)", res.StatusCode) + } + var data GetVideosResponse if err := json.NewDecoder(res.Body).Decode(&data); err != nil { return nil, err diff --git a/api/whispers/send_whisper.go b/api/whispers/send_whisper.go index 7f7f70f..35c55b1 100644 --- a/api/whispers/send_whisper.go +++ b/api/whispers/send_whisper.go @@ -3,6 +3,7 @@ package whispers import ( "context" "encoding/json" + "fmt" "io" "net/http" "net/url" @@ -70,5 +71,10 @@ func (c *Whispers) SendWhisper(ctx context.Context, params *SendWhisperParams, b } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return fmt.Errorf("failed to send whisper (%d)", res.StatusCode) + } + return nil } diff --git a/auth/token.go b/auth/token.go index 3eb6e8a..4f47e77 100644 --- a/auth/token.go +++ b/auth/token.go @@ -2,6 +2,7 @@ package auth import ( "encoding/json" + "fmt" "net/http" "strings" "time" @@ -58,6 +59,11 @@ func GetToken(params *GetTokenParams) (*Token, error) { } defer res.Body.Close() + statusOK := res.StatusCode >= 200 && res.StatusCode < 300 + if !statusOK { + return nil, fmt.Errorf("failed to get token (%d)", res.StatusCode) + } + var token Token if err := json.NewDecoder(res.Body).Decode(&token); err != nil { return nil, err