GET Error Codes
/error_codes
/error_codes/{error_code}
Paths
GET /error_codes
— returns all exposed error codes.GET /error_codes/{error_code}
— returns the message for one specific code, or 404 if not found/blacklisted.
Example Query:
https://base-hedger82.rasa.capital/error_codes
See this section for more information about error codes.
Error Codes Implementation (Rasa)
@common_router.get(
'/error_codes',
responses={status.HTTP_200_OK: {"model": ErrorCodeResponseSchema}},
response_model=ErrorCodeResponseSchema
)
async def get_all_error_codes():
return {
code: msg
for code, msg in ErrorCodes.items()
if code not in ErrorCodeBlackList
}
@common_router.get(
'/error_codes/{error_code}',
responses={status.HTTP_200_OK: {"model": ErrorCodeResponseSchema}},
response_model=ErrorCodeResponseSchema
)
async def get_error_message(error_code: int):
msg = ErrorCodes.get(error_code)
if msg is None or error_code in ErrorCodeBlackList:
raise ErrorCodeResponse(
status_code=404,
error=ErrorInfoContainer.error_code_not_found
)
return {error_code: msg}
Logic
Imports
from share.error_codes import ErrorCodes # a dict[int, str]
from db_tools.triggers.trigger_utils import ErrorCodeBlackList # a set[int]
ErrorCodes
is your master map of all possible error‐code → message entries.ErrorCodeBlackList
lists codes you don’t want to expose via the public API.
GET /error_codes
Filters out any blacklisted codes, then returns the rest as a plain dict.
GET /error_codes/{error_code}
Looks up the message via
ErrorCodes.get(error_code)
.If missing or blacklisted, raises an
ErrorCodeResponse(404)
.Otherwise returns
{ error_code: message }
.
Steps to Implement Your Own Version
Define the Error Codes
ErrorCodes = {
1001: "Insufficient balance",
1002: "Order timeout",
# …
}
ErrorCodeBlackList = {9999, 8888} # codes reserved for internal use
Create the Response Schema
class ErrorCodeResponseSchema(RootModel[Dict[int, str]]):
pass
Define an Exception (example)
class ErrorCodeResponse(HTTPException):
def __init__(self, status_code: int, error: ErrorInfoContainer):
super().__init__(status_code=status_code, detail=error.to_dict())
Add FastAPI Routes
In your
common_router
, register the two@common_router.get
endpoints exactly as above.Import
ErrorCodes
,ErrorCodeBlackList
,ErrorCodeResponse
, andErrorCodeResponseSchema
.
Last updated