Files
gsfdc/demo-dify/dify/web/app/components/billing/billing-error.ts
T
wuzilongandCursor 6519682885 chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动
演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-18 13:59:25 +08:00

29 lines
1003 B
TypeScript

import type {
BillingOperationFailedError,
BillingRequestInProgressError,
BillingUnavailableError,
} from '@dify/contracts/api/console/compliance/types.gen'
import { isDefinedError, ORPCError } from '@orpc/client'
type BillingErrorCode = (
| BillingOperationFailedError
| BillingRequestInProgressError
| BillingUnavailableError
)['code']
const billingErrorMessageKeyByCode = {
billing_operation_failed: 'errors.operationFailed',
billing_request_in_progress: 'errors.requestInProgress',
billing_unavailable: 'errors.unavailable',
} as const satisfies Record<BillingErrorCode, string>
function isBillingErrorCode(code: string): code is BillingErrorCode {
return Object.hasOwn(billingErrorMessageKeyByCode, code)
}
export function billingErrorMessageKey(error: unknown) {
if (error instanceof ORPCError && isDefinedError(error) && isBillingErrorCode(error.code))
return billingErrorMessageKeyByCode[error.code]
return billingErrorMessageKeyByCode.billing_operation_failed
}