fix: status command shows detailed API health (rate-limit, auth, unreachable)

checkHealth() now returns 'ok' | 'rate_limited' | 'auth_error' | 'unreachable'
instead of boolean, so /status can display the specific issue with color-coded
indicators instead of just "Nicht erreichbar" for all failures.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Martin Porwoll 2026-03-01 10:29:57 +00:00
parent a2ee6d8cbe
commit 11e91a26c1
2 changed files with 17 additions and 16 deletions

View file

@ -168,13 +168,18 @@ class PayloadClient {
return data.docs; return data.docs;
} }
async checkHealth(): Promise<boolean> { async checkHealth(): Promise<'ok' | 'rate_limited' | 'auth_error' | 'unreachable'> {
try { try {
const response = await this.authFetch(`${this.apiUrl}/users/me`); const response = await this.authFetch(`${this.apiUrl}/users/me`);
return response.ok; if (response.ok) return 'ok';
if (response.status === 401) return 'auth_error';
return 'unreachable';
} catch (error) { } catch (error) {
const msg = error instanceof Error ? error.message : '';
log.error('Health check failed', error); log.error('Health check failed', error);
return false; if (msg.includes('429') || msg.includes('RATE_LIMITED')) return 'rate_limited';
if (msg.includes('401') || msg.includes('incorrect')) return 'auth_error';
return 'unreachable';
} }
} }

View file

@ -384,18 +384,14 @@ export function registerHandlers(bot: Bot<BotContext>): void {
// /status command // /status command
bot.command('status', async (ctx) => { bot.command('status', async (ctx) => {
let apiStatus: string; const health = await payloadClient.checkHealth();
try { const apiLabels: Record<string, string> = {
const healthy = await payloadClient.checkHealth(); ok: '\ud83d\udfe2 Erreichbar',
apiStatus = healthy ? 'Erreichbar' : 'Nicht erreichbar'; rate_limited: '\ud83d\udfe1 Rate\\-Limit \\(bitte warten\\)',
} catch (error) { auth_error: '\ud83d\udd34 Anmeldefehler',
const msg = error instanceof Error ? error.message : ''; unreachable: '\ud83d\udd34 Nicht erreichbar',
if (msg.includes('429') || msg.includes('RATE_LIMITED')) { };
apiStatus = 'Rate\\-Limit \\(bitte warten\\)'; const apiStatus = apiLabels[health] ?? '\ud83d\udd34 Unbekannt';
} else {
apiStatus = 'Nicht erreichbar';
}
}
const expiry = payloadClient.getTokenExpiry(); const expiry = payloadClient.getTokenExpiry();
const expiryStr = expiry ? expiry.toLocaleString('de-DE') : 'Kein Token'; const expiryStr = expiry ? expiry.toLocaleString('de-DE') : 'Kein Token';
@ -407,7 +403,7 @@ export function registerHandlers(bot: Bot<BotContext>): void {
const text = const text =
`\ud83d\udcca *Bot Status*\n\n` + `\ud83d\udcca *Bot Status*\n\n` +
`\u23f1 Uptime: ${escapeMarkdown(formatUptime())}\n` + `\u23f1 Uptime: ${escapeMarkdown(formatUptime())}\n` +
`\ud83d\udfe2 API: ${apiStatus}\n` + `${apiStatus}\n` +
`\ud83c\udfe2 Tenant: ${tenantStr}\n` + `\ud83c\udfe2 Tenant: ${tenantStr}\n` +
`\ud83d\udd11 Token läuft ab: ${escapeMarkdown(expiryStr)}`; `\ud83d\udd11 Token läuft ab: ${escapeMarkdown(expiryStr)}`;