(status: number, body: ApiErrorBody, url?: string)
| 29 | } |
| 30 | |
| 31 | export function mapApiError(status: number, body: ApiErrorBody, url?: string): CLIError { |
| 32 | const apiMsg = |
| 33 | body.base_resp?.status_msg || |
| 34 | body.error?.message || |
| 35 | `HTTP ${status}`; |
| 36 | |
| 37 | const apiCode = body.base_resp?.status_code || body.error?.code; |
| 38 | |
| 39 | if (status === 401 || status === 403) { |
| 40 | return new CLIError( |
| 41 | `API key rejected (HTTP ${status}).`, |
| 42 | ExitCode.AUTH, |
| 43 | 'Check status: mmx auth status\nRe-authenticate: mmx auth login', |
| 44 | ); |
| 45 | } |
| 46 | |
| 47 | if (status === 429) { |
| 48 | return new CLIError( |
| 49 | `Rate limit or quota exceeded. ${apiMsg}`, |
| 50 | ExitCode.QUOTA, |
| 51 | 'Check usage: mmx quota show', |
| 52 | ); |
| 53 | } |
| 54 | |
| 55 | if (status === 408 || status === 504) { |
| 56 | return new CLIError( |
| 57 | `Request timed out (HTTP ${status}).`, |
| 58 | ExitCode.TIMEOUT, |
| 59 | 'Try increasing --timeout or retry later.', |
| 60 | ); |
| 61 | } |
| 62 | |
| 63 | // MiniMax content sensitivity filter |
| 64 | if (apiCode === 1002 || apiCode === 1039) { |
| 65 | const filterType = body.base_resp?.status_msg || 'content sensitivity'; |
| 66 | return new CLIError( |
| 67 | `Input content flagged by sensitivity filter (${filterType}).`, |
| 68 | ExitCode.CONTENT_FILTER, |
| 69 | ); |
| 70 | } |
| 71 | |
| 72 | // MiniMax insufficient quota |
| 73 | if (apiCode === 1028 || apiCode === 1030) { |
| 74 | const hint = planHintForUrl(url); |
| 75 | return new CLIError( |
| 76 | `Quota exhausted. ${apiMsg}`, |
| 77 | ExitCode.QUOTA, |
| 78 | `Check usage: mmx quota show${hint}\nUpgrade plan: ${upgradeUrl(url)}`, |
| 79 | ); |
| 80 | } |
| 81 | |
| 82 | // MiniMax model not supported by plan |
| 83 | if (apiCode === 2061) { |
| 84 | const hint = planHintForUrl(url); |
| 85 | return new CLIError( |
| 86 | `This model is not available on your current Token Plan. ${apiMsg}`, |
| 87 | ExitCode.QUOTA, |
| 88 | `Check usage: mmx quota show${hint}\nUpgrade plan: ${upgradeUrl(url)}`, |
no test coverage detected