From 6ed094e2d44df62a520ac8595543c90d2329402f Mon Sep 17 00:00:00 2001 From: bielie Date: Wed, 18 Feb 2026 18:13:26 +0800 Subject: [PATCH] Improve plugin-side API error observability for generation --- modules/streaming-generation.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/modules/streaming-generation.js b/modules/streaming-generation.js index 95b63be..50be008 100644 --- a/modules/streaming-generation.js +++ b/modules/streaming-generation.js @@ -287,10 +287,14 @@ class StreamingGeneration { const logSendRequestError = (err, streamMode) => { if (err?.name !== 'AbortError') { const safeApiUrl = String(cmdApiUrl || reverseProxy || oai_settings?.custom_url || '').trim(); + const status = this._extractHttpStatus(err); + const isRateLimit = status === 429; try { xbLog.error('streamingGeneration', 'sendRequest failed', { message: err?.message || String(err), name: err?.name, + status, + isRateLimit, stream: !!streamMode, api: String(opts.api || ''), model, @@ -299,6 +303,12 @@ class StreamingGeneration { }); } catch {} console.error('[xbgen:callAPI] sendRequest failed:', err); + if (status) { + console.error(`[xbgen:callAPI] HTTP status=${status} stream=${!!streamMode} api=${String(opts.api || '')} model=${model}`); + } + if (isRateLimit) { + console.error('[xbgen:callAPI] Rate limited (429). Check provider RPM/TPM and concurrent requests.'); + } } }; @@ -465,6 +475,14 @@ class StreamingGeneration { return String(session.text || ''); } + const httpStatus = this._extractHttpStatus(err); + if (!err?.error && httpStatus) { + err.error = { + code: String(httpStatus), + message: String(err?.message || `HTTP ${httpStatus}`), + }; + } + console.error('[StreamingGeneration] Generation error:', err); console.error('[StreamingGeneration] error.error =', err?.error); try { xbLog.error('streamingGeneration', `processGeneration error sid=${session.id}`, err); } catch {} @@ -812,6 +830,18 @@ class StreamingGeneration { return true; } + _extractHttpStatus(err) { + const direct = Number(err?.status || err?.statusCode || err?.response?.status); + if (Number.isFinite(direct) && direct >= 100 && direct <= 599) return direct; + const msg = String(err?.message || ''); + const m = msg.match(/\bstatus\s+(\d{3})\b/i); + if (m) { + const s = Number(m[1]); + if (Number.isFinite(s)) return s; + } + return null; + } + _getLastMessagesSnapshot() { const ctx = getContext(); const list = Array.isArray(ctx?.chat) ? ctx.chat : [];