This commit is contained in:
24
src/utils/business/exchangeError.ts
Normal file
24
src/utils/business/exchangeError.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
type BusinessFailure = {
|
||||
code?: number | string
|
||||
msg?: string
|
||||
message?: string
|
||||
data?: { phone?: unknown }
|
||||
}
|
||||
|
||||
const getBusinessFailure = (value: unknown): BusinessFailure | undefined => {
|
||||
if (!value || typeof value !== 'object') return undefined
|
||||
const candidate = value as { response?: { data?: BusinessFailure } } & BusinessFailure
|
||||
return candidate.response?.data || candidate
|
||||
}
|
||||
|
||||
export const getExchangePhoneConflictMessage = (value: unknown): string | undefined => {
|
||||
const failure = getBusinessFailure(value)
|
||||
if (Number(failure?.code) !== 1202) return undefined
|
||||
const phone = typeof failure?.data?.phone === 'string' ? failure.data.phone.trim() : ''
|
||||
return `新资产已绑定手机号${phone ? ` ${phone}` : ''},请先到『手机号资产关联』解除后再提交`
|
||||
}
|
||||
|
||||
export const getExchangeBusinessErrorMessage = (value: unknown): string | undefined => {
|
||||
const failure = getBusinessFailure(value)
|
||||
return failure?.msg || failure?.message
|
||||
}
|
||||
Reference in New Issue
Block a user