このコミットが含まれているのは:
2026-10-31 13:50:10 +09:00
コミット dba409c3e8
33個のファイルの変更、1490行の追加、236行の削除
+35 -2
ファイルの表示
@@ -1,4 +1,5 @@
import { fieldsForCounts, orderedCountFields, selectedCountChildren,
import { isApiError } from '@/lib/api'
import { countsMaskedValue, fieldsForCounts, orderedCountFields, selectedCountChildren,
sortedCountChildren } from '@/lib/counts'
import { countsEventTypes, countsFieldLabel } from '@/lib/countsDefinitions'
import { languageUIMessage, translateUIMessage } from '@/lib/i18n'
@@ -12,6 +13,37 @@ import type { CountsAxis, CountsDefinition } from '@/lib/countsDefinitions'
import type { LocaleCode } from '@/lib/locales'
// Render only known codes and numerical limits, never arbitrary server error text.
export const countsErrorMessage = (failure: unknown, locale: LocaleCode) => {
const response = isApiError (failure) ? failure.response : null
const body = (response?.data ?? failure) as {
error?: unknown; max_axes?: unknown; maxAxes?: unknown
max_columns?: unknown; maxColumns?: unknown } | null
const code = body != null && typeof body === 'object' ? body.error : null
const message = (key: string, values?: Record<string, string | number>) =>
translateUIMessage (key, 'counts', locale, values)
if (code === 'too_many_axes' || code === 'too_many_columns')
{
const maximum = code === 'too_many_axes' ? body?.maxAxes ?? body?.max_axes
: body?.maxColumns ?? body?.max_columns
if (typeof maximum === 'number')
return message (code === 'too_many_axes' ? 'axisLimit' : 'columnLimit.message', {
max: maximum })
}
if (code === 'private_condition') return message ('privateCondition')
if (code === 'counts_query_timeout' || code === 'generation_timeout')
return message ('errors.queryTimeout')
if (code === 'export_worker_unavailable' || code === 'worker_unavailable')
return message ('errors.workerUnavailable')
if (['worker_stalled', 'interrupted', 'generation_failed', 'export_too_large',
'export_storage_full'].includes (String (code))) return message ('errors.stopped')
if (response?.status === 401) return message ('errors.authentication')
if (response?.status === 403) return message ('errors.permission')
if (response?.status === 400 || response?.status === 422) return message ('errors.input')
return message ('common:fetchError')
}
export const countsFieldValue = (row: CountRecord, field: string): unknown =>
row[field] ?? row[field.replace (/_([a-z])/g, (_, letter: string) => letter.toUpperCase ())]
@@ -450,6 +482,7 @@ export const countsConditionValue = (
axis: CountsAxis, locale: LocaleCode, timezone: string,
labels?: Record<string, Record<string, string | null>>,
): string => {
if (value === countsMaskedValue) return '********'
if (axis.field === 'user' && value == null)
return translateUIMessage ('bot', 'counts', locale).text
if (value == null) return 'NULL'
@@ -488,7 +521,7 @@ export const countsSummaryValue = (
): string => {
const message = (key: string, values?: Record<string, string | number>) =>
translateUIMessage (key, 'counts', locale, values).text
if (value === '__counts_private__') return '********'
if (value === countsMaskedValue) return '********'
if (value == null) return axis.field === 'user' ? message ('bot') : ''
if (['language_code', 'source_language_code'].includes (axis.field))
return languageUIMessage (String (value), locale).text