Improve plugin-side API error observability for generation
This commit is contained in:
@@ -287,10 +287,14 @@ class StreamingGeneration {
|
|||||||
const logSendRequestError = (err, streamMode) => {
|
const logSendRequestError = (err, streamMode) => {
|
||||||
if (err?.name !== 'AbortError') {
|
if (err?.name !== 'AbortError') {
|
||||||
const safeApiUrl = String(cmdApiUrl || reverseProxy || oai_settings?.custom_url || '').trim();
|
const safeApiUrl = String(cmdApiUrl || reverseProxy || oai_settings?.custom_url || '').trim();
|
||||||
|
const status = this._extractHttpStatus(err);
|
||||||
|
const isRateLimit = status === 429;
|
||||||
try {
|
try {
|
||||||
xbLog.error('streamingGeneration', 'sendRequest failed', {
|
xbLog.error('streamingGeneration', 'sendRequest failed', {
|
||||||
message: err?.message || String(err),
|
message: err?.message || String(err),
|
||||||
name: err?.name,
|
name: err?.name,
|
||||||
|
status,
|
||||||
|
isRateLimit,
|
||||||
stream: !!streamMode,
|
stream: !!streamMode,
|
||||||
api: String(opts.api || ''),
|
api: String(opts.api || ''),
|
||||||
model,
|
model,
|
||||||
@@ -299,6 +303,12 @@ class StreamingGeneration {
|
|||||||
});
|
});
|
||||||
} catch {}
|
} catch {}
|
||||||
console.error('[xbgen:callAPI] sendRequest failed:', err);
|
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 || '');
|
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] Generation error:', err);
|
||||||
console.error('[StreamingGeneration] error.error =', err?.error);
|
console.error('[StreamingGeneration] error.error =', err?.error);
|
||||||
try { xbLog.error('streamingGeneration', `processGeneration error sid=${session.id}`, err); } catch {}
|
try { xbLog.error('streamingGeneration', `processGeneration error sid=${session.id}`, err); } catch {}
|
||||||
@@ -812,6 +830,18 @@ class StreamingGeneration {
|
|||||||
return true;
|
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() {
|
_getLastMessagesSnapshot() {
|
||||||
const ctx = getContext();
|
const ctx = getContext();
|
||||||
const list = Array.isArray(ctx?.chat) ? ctx.chat : [];
|
const list = Array.isArray(ctx?.chat) ? ctx.chat : [];
|
||||||
|
|||||||
Reference in New Issue
Block a user