From 8e749ac3bf048d2790496d2e8d23da476c56ff55 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Sat, 5 Sep 2020 20:59:17 -0400 Subject: handle http errors a bit better --- discord/discord.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'discord/discord.cpp') diff --git a/discord/discord.cpp b/discord/discord.cpp index 9cf9df4..02c11ea 100644 --- a/discord/discord.cpp +++ b/discord/discord.cpp @@ -108,6 +108,8 @@ void DiscordClient::UpdateSettingsGuildPositions(const std::vector &p nlohmann::json body; body["guild_positions"] = pos; m_http.MakePATCH("/users/@me/settings", body.dump(), [this, pos](const cpr::Response &r) { + if (!CheckCode(r)) return; + m_user_settings.GuildPositions = pos; m_abaddon->DiscordNotifyChannelListFullRefresh(); }); @@ -116,6 +118,8 @@ void DiscordClient::UpdateSettingsGuildPositions(const std::vector &p void DiscordClient::FetchMessagesInChannel(Snowflake id, std::function &)> cb) { std::string path = "/channels/" + std::to_string(id) + "/messages?limit=50"; m_http.MakeGET(path, [this, id, cb](cpr::Response r) { + if (!CheckCode(r)) return; + std::vector msgs; std::vector ids; @@ -449,6 +453,15 @@ void DiscordClient::SendIdentify() { m_websocket.Send(msg); } +bool DiscordClient::CheckCode(const cpr::Response &r) { + if (r.status_code >= 300) { + fprintf(stderr, "api request to %s failed with status code %d\n", r.url.c_str(), r.status_code); + return false; + } + + return true; +} + void DiscordClient::LoadEventMap() { m_event_map["READY"] = GatewayEvent::READY; m_event_map["MESSAGE_CREATE"] = GatewayEvent::MESSAGE_CREATE; -- cgit v1.2.3