fix(discord-adapter.c): check 429 response's 'global' field
@@ -135,20 +135,23 @@ discord_adapter_run(
logconf_fatal(&adapter->conf, "METHOD_NOT_ALLOWED: The server couldn't recognize the received HTTP method");
break;
case HTTP_TOO_MANY_REQUESTS: {
+ bool is_global = false;
char message[256] = "";
double retry_after = -1; /* seconds */
struct sized_buffer body = ua_info_get_resp_body(&adapter->err.info);
json_extract(body.start, body.size,
- "(message):s (retry_after):lf",
- message, &retry_after);
+ "(global):b (message):s (retry_after):lf",
+ &is_global, message, &retry_after);
+ VASSERT_S(retry_after != -1, "(NO RETRY-AFTER INCLUDED) %s", message);
- if (retry_after >= 0) { /* retry after attribute received */
+ if (is_global) {
logconf_warn(&adapter->conf, "GLOBAL RATELIMITING (wait: %.2lf ms) : %s", 1000*retry_after, message);
ua_block_ms(adapter->ua, (uint64_t)(1000*retry_after));
}
- else { /* no retry after included, we should abort */
- ERR("(NO RETRY-AFTER INCLUDED) %s", message);
+ else {
+ logconf_warn(&adapter->conf, "429 RATELIMITING (wait: %.2lf ms) : %s", 1000*retry_after, message);
+ cee_sleep_ms((int64_t)(1000*retry_after));
}
break; }
default:
