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_codesSee 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
ErrorCodesis your master map of all possible error‐code → message entries.ErrorCodeBlackListlists 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
Create the Response Schema
Define an Exception (example)
Add FastAPI Routes
In your
common_router, register the two@common_router.getendpoints exactly as above.Import
ErrorCodes,ErrorCodeBlackList,ErrorCodeResponse, andErrorCodeResponseSchema.
Last updated
