Fix messages occasionally not going through
Discord API will occasionally throw 502 Bad Gateway errors. Retrying normally means this is not a problem.
This commit is contained in:
@ -6,7 +6,7 @@ extern std::string bot_token;
|
||||
* Warning: (Awful) C Code
|
||||
*/
|
||||
|
||||
std::string HTTPHelper::post_request(std::string url, std::string content_type, std::string data) {
|
||||
std::string HTTPHelper::post_request(std::string url, std::string content_type, std::string data, long *response_code) {
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
std::string read_buffer;
|
||||
@ -37,8 +37,10 @@ std::string HTTPHelper::post_request(std::string url, std::string content_type,
|
||||
|
||||
res = curl_easy_perform(curl);
|
||||
|
||||
if (res != CURLE_OK) {
|
||||
return "ERROR";
|
||||
if (res == CURLE_OK) {
|
||||
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, response_code);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
|
||||
/* always cleanup */
|
||||
@ -50,6 +52,6 @@ std::string HTTPHelper::post_request(std::string url, std::string content_type,
|
||||
}
|
||||
|
||||
size_t HTTPHelper::write_callback(void *contents, size_t size, size_t nmemb, void *userp) {
|
||||
((std::string *) userp)->append((char *)contents, size * nmemb);
|
||||
((std::string *) userp)->append((char *) contents, size * nmemb);
|
||||
return size * nmemb;
|
||||
}
|
@ -7,7 +7,7 @@
|
||||
|
||||
class HTTPHelper {
|
||||
public:
|
||||
std::string post_request(std::string url, std::string content_type, std::string data);
|
||||
std::string post_request(std::string url, std::string content_type, std::string data, long *response_code);
|
||||
|
||||
private:
|
||||
static size_t write_callback(void *contents, size_t size, size_t nmemb, void *userp);
|
||||
|
Reference in New Issue
Block a user