Skip to content

Commit bfbb4cb

Browse files
authored
Merge pull request #256 from renaissance04/fix/search-output-sensitive
fix(search): map output sensitivity to content filter exit code
2 parents 74e904a + 8feefbc commit bfbb4cb

3 files changed

Lines changed: 37 additions & 1 deletion

File tree

‎ERRORS.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ No error scenarios — prints a message directing users to run `npm update -g mm
226226
| HTTP 401 / 403 | `API key rejected (HTTP ${status}).` |
227227
| HTTP 429 | `Rate limit or quota exceeded. ${apiMsg}` |
228228
| `status_code` 1002 / 1039 (content filter) | `Input content flagged by sensitivity filter (${filterType}).` |
229+
| `status_msg` contains "new_sensitive" / output sensitivity (HTTP 200) | `Output withheld by content moderation (${apiMsg}).` |
229230
| `status_code` 1028 / 1030 (quota exhausted) | `Quota exhausted. ${apiMsg}` |
230231
| `status_code` 2061 (model not on plan) | `This model is not available on your current Token Plan. ${apiMsg}` |
231232
| Other API errors | `API error: ${apiMsg} (HTTP ${status})` |

‎src/errors/api.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function mapApiError(status: number, body: ApiErrorBody, url?: string): C
7575
(/sensitive content/i.test(apiMsg) || /(?:^|\D)1026(?:\D|$)/.test(apiMsg));
7676

7777
// MiniMax content sensitivity filter
78-
if (apiCode === 1002 || apiCode === 1039 || isV2ContentFilter) {
78+
if (apiCode === 1002 || apiCode === 1039 || apiCode === 1026 || isV2ContentFilter) {
7979
const filterType =
8080
body.base_resp?.status_msg ||
8181
body.error?.message ||
@@ -106,6 +106,15 @@ export function mapApiError(status: number, body: ApiErrorBody, url?: string): C
106106
);
107107
}
108108

109+
// output sensitivity (status_code 1027, e.g. "output new_sensitive")
110+
if (apiCode === 1027 || /output.*sensitive/i.test(apiMsg)) {
111+
return new CLIError(
112+
`Output withheld by content moderation (${apiMsg}).`,
113+
ExitCode.CONTENT_FILTER,
114+
'Refine your query and try again.',
115+
);
116+
}
117+
109118
return new CLIError(
110119
`API error: ${apiMsg} (HTTP ${status})`,
111120
ExitCode.GENERAL,

‎test/errors/api.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,32 @@ describe('mapApiError', () => {
7373
expect(err.exitCode).toBe(ExitCode.QUOTA);
7474
});
7575

76+
it('maps output sensitivity (HTTP 200) to CONTENT_FILTER', () => {
77+
const err = mapApiError(200, {
78+
base_resp: { status_code: 2001, status_msg: 'output new_sensitive' },
79+
});
80+
expect(err.exitCode).toBe(ExitCode.CONTENT_FILTER);
81+
expect(err.message).toContain('content moderation');
82+
expect(err.message).toContain('output new_sensitive');
83+
expect(err.hint).toBeDefined();
84+
});
85+
86+
it('maps output sensitivity code 1027 to CONTENT_FILTER', () => {
87+
const err = mapApiError(200, {
88+
base_resp: { status_code: 1027, status_msg: '输出内容涉敏' },
89+
});
90+
expect(err.exitCode).toBe(ExitCode.CONTENT_FILTER);
91+
});
92+
93+
it('maps input sensitivity code 1026 to CONTENT_FILTER (not output)', () => {
94+
const err = mapApiError(200, {
95+
base_resp: { status_code: 1026, status_msg: 'input new_sensitive' },
96+
});
97+
expect(err.exitCode).toBe(ExitCode.CONTENT_FILTER);
98+
expect(err.message).toContain('Input');
99+
expect(err.message).not.toContain('Output withheld');
100+
});
101+
76102
it('maps unknown errors to GENERAL', () => {
77103
const err = mapApiError(500, { base_resp: { status_code: 0, status_msg: 'internal error' } });
78104
expect(err.exitCode).toBe(ExitCode.GENERAL);

0 commit comments

Comments
 (0)