26 lines
990 B
TypeScript
26 lines
990 B
TypeScript
import type { CodingRuntimePublicError } from '../contracts';
|
|
import { isAIGatewayUserContextMissing } from '../../../shared/ai-gateway-error-details';
|
|
import { getAIGatewayErrorKind } from '../../../shared/ai-gateway-error-kind';
|
|
|
|
export function projectPiProviderFailure(message: unknown): CodingRuntimePublicError {
|
|
if (typeof message === 'string' && isAIGatewayUserContextMissing(message)) {
|
|
return {
|
|
code: 'CODING_PROVIDER_AUTH_REQUIRED',
|
|
message: '模型服务身份上下文无效,请重试;若仍失败请重新登录。',
|
|
recoverable: true,
|
|
};
|
|
}
|
|
if (typeof message === 'string' && getAIGatewayErrorKind(message) === 'quota_exhausted') {
|
|
return {
|
|
code: 'CODING_PROVIDER_QUOTA_EXHAUSTED',
|
|
message: '词元点数余额不足,请充值后重试。',
|
|
recoverable: false,
|
|
};
|
|
}
|
|
return {
|
|
code: 'CODING_RUNTIME_START_FAILED',
|
|
message: '模型服务请求失败,请稍后重试。',
|
|
recoverable: true,
|
|
};
|
|
}
|