From 11e91a26c1b7face84434544988d669e457e5f81 Mon Sep 17 00:00:00 2001 From: Martin Porwoll Date: Sun, 1 Mar 2026 10:29:57 +0000 Subject: [PATCH] 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 --- src/payload/client.ts | 11 ++++++++--- src/telegram/handlers.ts | 22 +++++++++------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/payload/client.ts b/src/payload/client.ts index 2d2e821..a5b7a8a 100644 --- a/src/payload/client.ts +++ b/src/payload/client.ts @@ -168,13 +168,18 @@ class PayloadClient { return data.docs; } - async checkHealth(): Promise { + async checkHealth(): Promise<'ok' | 'rate_limited' | 'auth_error' | 'unreachable'> { try { 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) { + const msg = error instanceof Error ? error.message : ''; 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'; } } diff --git a/src/telegram/handlers.ts b/src/telegram/handlers.ts index 959d591..69d1b75 100644 --- a/src/telegram/handlers.ts +++ b/src/telegram/handlers.ts @@ -384,18 +384,14 @@ export function registerHandlers(bot: Bot): void { // /status command bot.command('status', async (ctx) => { - let apiStatus: string; - try { - const healthy = await payloadClient.checkHealth(); - apiStatus = healthy ? 'Erreichbar' : 'Nicht erreichbar'; - } catch (error) { - const msg = error instanceof Error ? error.message : ''; - if (msg.includes('429') || msg.includes('RATE_LIMITED')) { - apiStatus = 'Rate\\-Limit \\(bitte warten\\)'; - } else { - apiStatus = 'Nicht erreichbar'; - } - } + const health = await payloadClient.checkHealth(); + const apiLabels: Record = { + ok: '\ud83d\udfe2 Erreichbar', + rate_limited: '\ud83d\udfe1 Rate\\-Limit \\(bitte warten\\)', + auth_error: '\ud83d\udd34 Anmeldefehler', + unreachable: '\ud83d\udd34 Nicht erreichbar', + }; + const apiStatus = apiLabels[health] ?? '\ud83d\udd34 Unbekannt'; const expiry = payloadClient.getTokenExpiry(); const expiryStr = expiry ? expiry.toLocaleString('de-DE') : 'Kein Token'; @@ -407,7 +403,7 @@ export function registerHandlers(bot: Bot): void { const text = `\ud83d\udcca *Bot Status*\n\n` + `\u23f1 Uptime: ${escapeMarkdown(formatUptime())}\n` + - `\ud83d\udfe2 API: ${apiStatus}\n` + + `${apiStatus}\n` + `\ud83c\udfe2 Tenant: ${tenantStr}\n` + `\ud83d\udd11 Token läuft ab: ${escapeMarkdown(expiryStr)}`;