Skip to content

Response Codes

All APIs return a unified format: {"code": "xxxx", "msg": "...", "data": ...}

Response codes are defined in app/core/code.py.

0000 — Success

CodeConstantDescription
0000SUCCESSRequest successful

1xxx — System Errors

Automatically caught by framework exception handlers.

CodeConstantDescription
1000INTERNAL_ERRORUncaught internal exception
1100INTEGRITY_ERRORDatabase constraint violation (unique, foreign key)
1101NOT_FOUNDRecord does not exist
1200REQUEST_VALIDATIONRequest parameter validation failed
1201RESPONSE_VALIDATIONResponse serialization failed

2xxx — Business Logic Errors

21xx — Authentication

CodeConstantDescriptionFrontend Action
2100INVALID_TOKENToken invalid / missing / decode failedRedirect to login
2101INVALID_SESSIONToken type wrong / user not foundRedirect to login
2102ACCOUNT_DISABLEDAccount is disabledModal confirm, then logout
2103TOKEN_EXPIREDToken has expiredAuto-refresh token

22xx — Authorization

CodeConstantDescriptionFrontend Action
2200API_DISABLEDAPI endpoint is disabledShow error message
2201PERMISSION_DENIEDRBAC permission deniedShow error message

23xx — Resource Conflict

CodeConstantDescription
2300DUPLICATE_RESOURCEDuplicate resource (username, role code, etc.)

24xx — General Business Failure

CodeConstantDescription
2400FAILGeneral business failure

3xxx — Reserved

Reserved for future framework extensions.

4000-9999 — User-Defined

For custom business logic. The frontend will not auto-display error messages for these codes — callers must handle them explicitly.

Exception Handlers

Defined in app/core/exceptions.py:

ExceptionCodeDescription
IntegrityError1100Database constraint violation
DoesNotExist1101Record not found
RequestValidationError1200Pydantic validation failed
ResponseValidationError1201Response serialization failed
Uncaught exceptions1000Internal server error

Frontend Environment Variables

bash
VITE_SERVICE_SUCCESS_CODE=0000
VITE_SERVICE_LOGOUT_CODES=2100,2101
VITE_SERVICE_MODAL_LOGOUT_CODES=2102
VITE_SERVICE_EXPIRED_TOKEN_CODES=2103

基于 MIT 协议发布