feat(ai): понятные ошибки провайдера вместо 'AI service error: <статус>'
Хелпер lib/ai-errors.js маппит HTTP-статус ответа провайдера на человеческое пояснение (402 — закончились лимиты, 401 — ключ, 429 — лимит запросов и т.д.) и добавляет короткий текст ошибки провайдера из тела ответа. Подключён во всех точках вызова модели: воркеры записей/отчётов/отзывов/заметок, aiComplete, probeAiModel.
This commit is contained in:
@@ -67,6 +67,7 @@ const { lessonReportWriteBlocked } = require('./lib/lesson-reports');
|
||||
const { groupOwnedBy } = require('./lib/groups');
|
||||
const { ensureProjectFileSizeColumn, backfillProjectFileSizes } = require('./lib/file-sizes');
|
||||
const { resolveImgbbEndpoint, friendlyApiError } = require('./lib/feedback-imgbb');
|
||||
const { aiHttpErrorFromResponse, aiHttpErrorText, aiHttpErrorDetail } = require('./lib/ai-errors');
|
||||
const { findBrokenFaceRefs, scanAllBrokenFaceRefs, cleanupAllBrokenFaceRefs, deleteFaceRef } = require('./lib/photo-cleanup');
|
||||
const {
|
||||
ensureDocsTables,
|
||||
@@ -6994,7 +6995,7 @@ async function probeAiModel(model) {
|
||||
const latency_ms = Date.now() - startedAt;
|
||||
if (!r.ok) {
|
||||
const t = await r.text().catch(() => '');
|
||||
return { ok: false, latency_ms, error: `HTTP ${r.status}${t ? ': ' + t.slice(0, 200) : ''}` };
|
||||
return { ok: false, latency_ms, error: aiHttpErrorText(r.status, aiHttpErrorDetail(t)) };
|
||||
}
|
||||
const d = await r.json();
|
||||
const sample = (d.choices?.[0]?.message?.content || '').trim();
|
||||
@@ -7040,7 +7041,7 @@ async function aiComplete(systemPrompt, userText, maxTokensOverride, profileOver
|
||||
max_tokens: maxTokens
|
||||
})
|
||||
});
|
||||
if (!res.ok) throw new Error(`AI service error: ${res.status}`);
|
||||
if (!res.ok) throw await aiHttpErrorFromResponse(res);
|
||||
const data = await res.json();
|
||||
return data.choices?.[0]?.message?.content?.trim() || '';
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user