diff --git a/src/config/apiRetCode.ts b/src/config/apiRetCode.ts
index f905ab7..b3704ac 100644
--- a/src/config/apiRetCode.ts
+++ b/src/config/apiRetCode.ts
@@ -1,26 +1,32 @@
/**
* API返回码常量定义
- * 迁移自 legacy/src/app/apiretcode.jsx
+ * 与后端 mmfcapi 的 `ApiReturnCode` 枚举(src/WebApplication2/Types/ApiReturnCode.cs)保持一致。
+ * 4XXXX 为请求错误(前三位对应最接近的 HTTP 状态码),6XXXX 为账号错误。
*/
-export const CODE_PERMISSION_DENIED = -127;
-export const CODE_NOT_LOGGED_IN = -1;
+export const CODE_SUCCESS = 114514;
+export const CODE_ERROR = -114514;
-export const CODE_ALREADY_LOGGED_IN = 0;
-export const CODE_INVALID_INVITE_CODE = 1;
-export const CODE_PASSWORD_IS_EMPTY = 2;
-export const CODE_INVALID_EMAIL_ADDRESS = 3;
-export const CODE_USERNAME_ALREADY_EXISTS = 4;
-export const CODE_EMAIL_ALREADY_EXISTS = 5;
-export const CODE_INVALID_VALUE = 6;
-export const CODE_PAYLOAD_REQUIRED = 7;
-export const CODE_FORMAT_NOT_SUPPORTED = 8;
-export const CODE_PAYLOAD_TOO_LARGE = 9;
-export const CODE_INVALID_CREDENTIALS = 10;
-export const CODE_LOGIN_FAILED_PENDING_VERIFCATION = 11;
-export const CODE_LOGIN_FAILED_USER_BANNED = 12;
+// 请求错误 4XXXX
+export const CODE_INVALID_VALUE = 40000;
+export const CODE_PAYLOAD_REQUIRED = 40001;
+export const CODE_NO_SUCH_ITEM = 40400;
+export const CODE_ITEM_ALREADY_EXISTS = 40900;
+export const CODE_ITEM_DELETED = 41000;
+export const CODE_PAYLOAD_TOO_LARGE = 41300;
+export const CODE_FORMAT_NOT_SUPPORTED = 41500;
+export const CODE_TOO_MANY_REQUESTS = 42900;
-export const CODE_NO_SUCH_ITEM = 13;
+// 账号错误 6XXXX
+export const CODE_NOT_LOGGED_IN = 60000;
+export const CODE_ALREADY_LOGGED_IN = 60001;
+export const CODE_PERMISSION_DENIED = 60002;
+export const CODE_INVALID_CREDENTIALS = 60003;
+export const CODE_LOGIN_FAILED_PENDING_VERIFCATION = 60004;
+export const CODE_LOGIN_FAILED_USER_BANNED = 60005;
-export const CODE_SUCCESS = 114514;
-export const CODE_ERROR = -114514;
+export const CODE_INVALID_INVITE_CODE = 60100;
+export const CODE_PASSWORD_IS_EMPTY = 60101;
+export const CODE_INVALID_EMAIL_ADDRESS = 60102;
+export const CODE_USERNAME_ALREADY_EXISTS = 60103;
+export const CODE_EMAIL_ALREADY_EXISTS = 60104;
diff --git a/test/components/score/ScoreCount.test.tsx b/test/components/score/ScoreCount.test.tsx
index b42a867..f65e64b 100644
--- a/test/components/score/ScoreCount.test.tsx
+++ b/test/components/score/ScoreCount.test.tsx
@@ -24,7 +24,7 @@ it('renders nested players/acc.dx from the new all-player totals endpoint', asyn
});
it('shows the avatar from the player profile and looks up only players without one', async () => {
const fetch = vi.fn(async (url: string) => url.includes('/account/profile?')
- ? Response.json({ code: 13, message: 'No such user' }, { status: 404 })
+ ? Response.json({ code: 40400, message: 'No such user' }, { status: 404 })
: Response.json({ geneTime: '2026-10-01T00:00:00Z', players: [
{ userId: 'u1', username: 'player', acc: { dx: 202.3456, classic: 205 }, player: { id: 'u1', username: 'player', nickname: 'Nick', avatarId: 'abc' } },
{ userId: 'u2', username: 'ghost', acc: { dx: 100, classic: 100 }, player: null },
diff --git a/test/components/song/SongComments.test.tsx b/test/components/song/SongComments.test.tsx
index 5dbdef4..0080e84 100644
--- a/test/components/song/SongComments.test.tsx
+++ b/test/components/song/SongComments.test.tsx
@@ -223,7 +223,7 @@ describe('CommentSection', () => {
it('asks a signed-out visitor to sign in and shows failures with a retry', async () => {
currentUser = null;
- fetchMock.mockResolvedValueOnce(json({ code: 13, message: 'No such chart' }, 404)).mockResolvedValueOnce(json(page([])));
+ fetchMock.mockResolvedValueOnce(json({ code: 40400, message: 'No such chart' }, 404)).mockResolvedValueOnce(json(page([])));
await render();
expect(container.textContent).toContain('登录后即可评论');
expect(container.querySelector('a[href^="/login?redirect="]')).toBeTruthy();
diff --git a/test/components/user/UserAvatar.test.tsx b/test/components/user/UserAvatar.test.tsx
index 216f8ef..3bc924b 100644
--- a/test/components/user/UserAvatar.test.tsx
+++ b/test/components/user/UserAvatar.test.tsx
@@ -59,7 +59,7 @@ describe('UserAvatar', () => {
});
it('falls back to the default avatar when the user does not exist', async () => {
- fetchMock.mockImplementation(async () => Response.json({ code: 13, message: 'No such user' }, { status: 404 }));
+ fetchMock.mockImplementation(async () => Response.json({ code: 40400, message: 'No such user' }, { status: 404 }));
await render();
expect(sources()).toEqual(['/api3/api/avatar/default']);
});
diff --git a/test/hooks/favorites.test.ts b/test/hooks/favorites.test.ts
index 9bc044c..9f3e749 100644
--- a/test/hooks/favorites.test.ts
+++ b/test/hooks/favorites.test.ts
@@ -9,6 +9,6 @@ it('derives favorite collection counts from songHashs', async () => {
expect(result[0]).toMatchObject({ id: 'collection', count: 2 });
});
it('does not convert an unauthorized response into favorite collection data', async () => {
- vi.stubGlobal('fetch', vi.fn().mockResolvedValue(Response.json({ code: -1 }, { status: 401 })));
+ vi.stubGlobal('fetch', vi.fn().mockResolvedValue(Response.json({ code: 60000 }, { status: 401 })));
await expect(fetchFavoriteCollections(endpoints.favorite.list)).rejects.toMatchObject({ status: 401 });
});
diff --git a/test/pages/ForginsterPage.test.tsx b/test/pages/ForginsterPage.test.tsx
index 05b06d2..d9ed448 100644
--- a/test/pages/ForginsterPage.test.tsx
+++ b/test/pages/ForginsterPage.test.tsx
@@ -108,7 +108,7 @@ describe('email challenge authentication', () => {
});
it('requires a fresh challenge after registration validation consumes it', async () => {
- fetchMock.mockResolvedValueOnce(new Response('key')).mockResolvedValueOnce(Response.json({ code: 4, message: 'Username exists' }, { status: 400 }));
+ fetchMock.mockResolvedValueOnce(new Response('key')).mockResolvedValueOnce(Response.json({ code: 60103, message: 'Username exists' }, { status: 400 }));
await render('/register'); fill('email', 'one@example.com'); await sendCode();
fill('username', 'player'); fill('nickname', 'player'); fill('password', 'x'); fill('password2', 'x'); fill('challengeCode', '12345678'); await submit();
expect(mocks.error).toHaveBeenCalledWith(i18n.t('auth/ForginsterPage.UsernameExists')); expect(submitButton().disabled).toBe(true);
diff --git a/test/utils/apiClient.test.ts b/test/utils/apiClient.test.ts
index 89dafe9..7874edc 100644
--- a/test/utils/apiClient.test.ts
+++ b/test/utils/apiClient.test.ts
@@ -14,8 +14,8 @@ describe('backend response formats', () => {
});
it('preserves the backend code and message on failure', async () => {
- vi.stubGlobal('fetch', vi.fn().mockResolvedValue(Response.json({ code: 10, message: 'Invalid code' }, { status: 400 })));
- await expect(apiRequest('/api')).rejects.toMatchObject({ status: 400, code: 10, message: 'Invalid code' });
+ vi.stubGlobal('fetch', vi.fn().mockResolvedValue(Response.json({ code: 60003, message: 'Invalid code' }, { status: 400 })));
+ await expect(apiRequest('/api')).rejects.toMatchObject({ status: 400, code: 60003, message: 'Invalid code' });
});
it('handles a proxy HTML error without displaying markup', async () => {