Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/agent-core/src/errors/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function makeErrorPayload(
*
* Recognized errors:
* - `KimiError`: passthrough.
* - `APIStatusError`: 429 -> rate_limit, 401 -> auth_error, otherwise -> api_error.
* - `APIStatusError`: 429 -> rate_limit, 401/403 -> auth_error, otherwise -> api_error.
* - `APIConnectionError` / `APITimeoutError`: connection_error.
* - `ChatProviderError`: api_error.
*
Expand All @@ -79,7 +79,7 @@ export function toKimiErrorPayload(error: unknown): KimiErrorPayload {
const code: KimiErrorCode =
error.statusCode === 429
? ErrorCodes.PROVIDER_RATE_LIMIT
: error.statusCode === 401
: error.statusCode === 401 || error.statusCode === 403
? ErrorCodes.PROVIDER_AUTH_ERROR
: ErrorCodes.PROVIDER_API_ERROR;
return {
Expand Down
23 changes: 23 additions & 0 deletions packages/agent-core/test/errors/serialize.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { APIStatusError } from '@moonshot-ai/kosong';
import { describe, expect, it } from 'vitest';

import { ErrorCodes, toKimiErrorPayload } from '../../src/errors';

describe('toKimiErrorPayload', () => {
it('classifies provider 403 responses as auth errors', () => {
const payload = toKimiErrorPayload(
new APIStatusError(403, 'access_terminated: Access was terminated', 'req-403'),
);

expect(payload).toMatchObject({
code: ErrorCodes.PROVIDER_AUTH_ERROR,
message: 'access_terminated: Access was terminated',
name: 'APIStatusError',
details: {
statusCode: 403,
requestId: 'req-403',
},
retryable: false,
});
});
});