Skip to content

Commit

Permalink
fix ratelimit retry
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkrissym committed Sep 15, 2024
1 parent 996cd15 commit bfb84ac
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
5 changes: 3 additions & 2 deletions Discord.C++/DiscordObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ json DiscordCPP::BaseDiscordObject::api_call(const std::string& url, const std::
code = response.status_code;

if (code == 429) {
Logger("discord.object.api_call").debug("Rate limit exceeded. Retry after: " + response.headers.at("Retry-After"));
float retry_after = get_or_else<float>(ret, "retry_after", 1.0f);
Logger("discord.object.api_call").debug("Rate limit exceeded. Retry after: " + std::to_string(retry_after) + " seconds");

std::this_thread::sleep_for(std::chrono::seconds(atoi(response.headers.at("Retry-After").c_str())));
std::this_thread::sleep_for(std::chrono::milliseconds((int)(retry_after * 1000.0f)));
}
}

Expand Down
3 changes: 1 addition & 2 deletions Discord.C++/DiscordObject.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#pragma once
#include <iostream>

#include <map>
#include <string>

#include "Exceptions.h"
#include "static.h"

namespace DiscordCPP {
Expand Down

0 comments on commit bfb84ac

Please sign in to comment.