17 lines
715 B
TypeScript
17 lines
715 B
TypeScript
import { AppError } from '@/lib/error-model';
|
|
|
|
export const APPLICATION_RETRY_MESSAGE = '网络可能不稳定,请再点一次「应用」。';
|
|
|
|
export function applicationErrorMessage(error: unknown): string {
|
|
if (error instanceof AppError) {
|
|
const status = error.details?.status;
|
|
const rejected = error.details?.commandOutcome === 'definitive_failure'
|
|
|| (typeof status === 'number' && status >= 400 && status < 500);
|
|
if (!rejected && (error.code === 'NETWORK' || error.code === 'TIMEOUT'
|
|
|| error.details?.backendCode === 'cloud_service_unavailable')) {
|
|
return APPLICATION_RETRY_MESSAGE;
|
|
}
|
|
}
|
|
return error instanceof Error ? error.message : '操作失败,请重试';
|
|
}
|