rename path: fix env-var mismatch, gut canRename gate, add primary-bot fallback on 401/403/429
- secondary rename-bot token was set as RENAME_TOKEN in .env but utils/renamer.js reads RENAMER_BOT; silently no-op'd every rename (host .env renamed separately)
- services/tickets.js canRename gutted to an always-ok shim; Mongo 2/10min per-channel gate is redundant since renames flow through RENAMER_BOT's own bucket. Ticket.renameCount / renameWindowStart remain as orphan fields (no migration)
- handlers/buttons.js + commands.js: drop the four "Channel renamed too quickly" else-branches and the rename-countdown label suffix; replace .catch(() => {}) with .catch(err => logError('rename', err)...)
- services/channelQueue.js: executeRename falls back to channel.setName(currentName) when renamer throws err.fallback === true (401/403/429); classifies non-fallback errors as renameQueue:token/permission (401/403) or renameQueue:secondary-bot ratelimited (429)
- utils/renamer.js: on 401/403 throw err.fallback=true immediately; on 429 respect retry_after up to 2000ms then throw err.fallback=true
- docs: align CLAUDE.md, docs/api/DISCORD_API_VALIDATION.md, docs/architecture/CRITICAL_FILES_AND_HOW_IT_WORKS.md
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -39,12 +39,30 @@ async function renameChannel(channelId, newName) {
|
||||
}
|
||||
|
||||
if (res.status === 429) {
|
||||
const retryAfter = (body && typeof body === 'object' && body.retry_after) || null;
|
||||
logWarn('renamer', `429 rename channel=${channelId} retry_after=${retryAfter}`).catch(() => {});
|
||||
const err = new Error(`rename 429: retry_after=${retryAfter}`);
|
||||
const retryAfterSec = (body && typeof body === 'object' && body.retry_after) || null;
|
||||
const retryAfterMs = retryAfterSec != null ? Math.ceil(Number(retryAfterSec) * 1000) : null;
|
||||
logWarn('renamer', `429 rename channel=${channelId} retry_after=${retryAfterSec}`).catch(() => {});
|
||||
|
||||
// Respect retry_after up to 2000ms; otherwise fail over immediately.
|
||||
if (retryAfterMs != null && retryAfterMs > 0 && retryAfterMs <= 2000) {
|
||||
await new Promise((resolve) => setTimeout(resolve, retryAfterMs));
|
||||
}
|
||||
|
||||
const err = new Error(`rename 429: retry_after=${retryAfterSec}`);
|
||||
err.status = 429;
|
||||
err.retryAfter = retryAfter;
|
||||
err.retryAfter = retryAfterSec;
|
||||
err.body = body;
|
||||
err.fallback = true;
|
||||
throw err;
|
||||
}
|
||||
|
||||
if (res.status === 401 || res.status === 403) {
|
||||
const bodyStr = typeof body === 'string' ? body : JSON.stringify(body);
|
||||
logWarn('renamer', `${res.status} rename channel=${channelId} body=${bodyStr}`).catch(() => {});
|
||||
const err = new Error(`rename ${res.status}: ${bodyStr}`);
|
||||
err.status = res.status;
|
||||
err.body = body;
|
||||
err.fallback = true;
|
||||
throw err;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user