Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions composables/billing/importError.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { expect, test } from 'bun:test'
import { readFileSync } from 'node:fs'
import { isImportCatalogUnavailable } from './importError'

test('recognizes Home catalog fetch failures without exposing diagnostic messages', () => {
expect(isImportCatalogUnavailable({ statusCode: 502, data: { error: 'models_dev_fetch_failed', message: 'private catalog URL' } })).toBe(true)
})
test('does not misclassify other gateway errors or unsupported deployments', () => {
for (const cause of [null, 'models_dev_fetch_failed', {}, { statusCode: 502 }, { statusCode: 502, data: 'models_dev_fetch_failed' }, { statusCode: 500, data: { error: 'models_dev_fetch_failed' } }, { statusCode: 502, data: { error: 'billing_import_preview_failed' } }, { statusCode: 404 }]) {
expect(isImportCatalogUnavailable(cause)).toBe(false)
}
})
test('preview localizes catalog failures while retaining unsupported endpoint fallback', () => {
const source = readFileSync(new URL('./useBillingPriceImport.ts', import.meta.url), 'utf8')
expect(source).toContain("isImportCatalogUnavailable(cause) ? t('billing.import.err.catalog')")
expect(source).toContain('[404, 405, 501].includes(cause?.statusCode)')
})
7 changes: 7 additions & 0 deletions composables/billing/importError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Home returns a stable error code separately from its diagnostic message.
export function isImportCatalogUnavailable(cause: unknown): boolean {
if (!cause || typeof cause !== 'object') return false
const error = cause as { statusCode?: unknown; data?: unknown }
if (error.statusCode !== 502 || !error.data || typeof error.data !== 'object') return false
return (error.data as { error?: unknown }).error === 'models_dev_fetch_failed'
}
3 changes: 2 additions & 1 deletion composables/billing/useBillingPriceImport.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isImportCatalogUnavailable } from './importError'
import { resolveImportSelection } from './importSelection'
import { scopeImportMatches } from './importMatches'
import { billingImportApplySupportError, createBillingImportIdempotencyKey, billingImportStorageKey, isDefinitiveBillingImportFailure, readBillingImportPending, validateBillingImportResult, writeBillingImportPending, type BillingImportPendingApply } from '~/composables/billingImport'
Expand Down Expand Up @@ -318,7 +319,7 @@ async function previewPrices(updates = false, preferredSelection?: string[]) {
} catch (cause: any) {
if (!disposed && session === sessionVersion && !controller.signal.aborted && version === inputVersion) {
if ([404, 405, 501].includes(cause?.statusCode)) importUnavailable.value = true
else error.value = cause?.message || t('billing.import.err.preview')
else error.value = isImportCatalogUnavailable(cause) ? t('billing.import.err.catalog') : cause?.message || t('billing.import.err.preview')
}
} finally {
if (!disposed && session === sessionVersion && previewController === controller) {
Expand Down
2 changes: 2 additions & 0 deletions locales/admin/billing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ export default defineAdminMessages({
'billing.import.err.rowMultiplier': 'Row multipliers need distinct nonempty keys and positive values.',
'billing.import.err.override': 'Each match override must identify a distinct requested target and a catalog provider/model.',
'billing.import.err.preview': 'Unable to preview model prices.',
'billing.import.err.catalog': 'Unable to load the price catalog. Please try again later.',
'billing.import.err.initializing': 'Import recovery is still initializing. Wait before applying prices.',
'billing.import.err.saveRecovery': 'Unable to save the recovery request. Nothing was sent; enable session storage before applying.',
'billing.import.err.clearRecovery': 'Unable to clear the saved recovery request. It has been retained.',
Expand Down Expand Up @@ -817,6 +818,7 @@ export default defineAdminMessages({
'billing.import.err.rowMultiplier': 'Pengali baris memerlukan key berbeda yang tidak kosong dan nilai positif.',
'billing.import.err.override': 'Setiap override pencocokan harus menunjuk target berbeda yang diminta dan provider/model katalog.',
'billing.import.err.preview': 'Gagal membuat pratinjau harga model.',
'billing.import.err.catalog': 'Gagal memuat katalog harga. Coba lagi nanti.',
'billing.import.err.initializing': 'Pemulihan impor masih diinisialisasi. Tunggu sebelum menerapkan harga.',
'billing.import.err.saveRecovery': 'Gagal menyimpan request pemulihan. Tidak ada yang dikirim; aktifkan session storage sebelum menerapkan.',
'billing.import.err.clearRecovery': 'Gagal menghapus request pemulihan tersimpan. Request tersebut tetap disimpan.',
Expand Down
1 change: 1 addition & 0 deletions locales/admin/ru/billing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ export default {
'billing.import.err.rowMultiplier': 'Для множителей строк нужны уникальные непустые ключи и положительные значения.',
'billing.import.err.override': 'Каждое переопределение сопоставления должно указывать уникальную запрошенную цель и провайдера/модель каталога.',
'billing.import.err.preview': 'Не удалось выполнить предпросмотр цен моделей.',
'billing.import.err.catalog': 'Не удалось загрузить каталог цен. Повторите попытку позже.',
'billing.import.err.initializing': 'Восстановление импорта ещё инициализируется. Подождите перед применением цен.',
'billing.import.err.saveRecovery': 'Не удалось сохранить запрос восстановления. Ничего не отправлено; включите session storage перед применением.',
'billing.import.err.clearRecovery': 'Не удалось очистить сохранённый запрос восстановления. Он сохранён.',
Expand Down
1 change: 1 addition & 0 deletions locales/admin/zh-CN/billing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ export default {
'billing.import.err.rowMultiplier': '行倍率需要互不相同的非空键和正数值。',
'billing.import.err.override': '每个匹配覆盖必须指定唯一的请求目标和目录提供商/模型。',
'billing.import.err.preview': '无法预览模型价格。',
'billing.import.err.catalog': '无法加载价格目录,请稍后重试。',
'billing.import.err.initializing': '导入恢复仍在初始化。请稍候再应用价格。',
'billing.import.err.saveRecovery': '无法保存恢复请求。未发送任何内容;请先启用会话存储再应用。',
'billing.import.err.clearRecovery': '无法清除已保存的恢复请求,已予以保留。',
Expand Down
1 change: 1 addition & 0 deletions locales/admin/zh-TW/billing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ export default {
'billing.import.err.rowMultiplier': '列倍率需要不重複的非空鍵值與正數值。',
'billing.import.err.override': '每個比對覆寫都必須指定不重複的請求目標,以及目錄供應商/模型。',
'billing.import.err.preview': '無法預覽模型價格。',
'billing.import.err.catalog': '無法載入價格目錄,請稍後重試。',
'billing.import.err.initializing': '匯入復原仍在初始化中。請稍候再套用價格。',
'billing.import.err.saveRecovery': '無法儲存復原請求。未傳送任何內容;套用前請啟用工作階段儲存空間。',
'billing.import.err.clearRecovery': '無法清除已儲存的復原請求,已保留該請求。',
Expand Down
Loading