jsonrpc.BaseError¶
Base class for JSON-RPC errors. Subclass it to define your own error types.
class NotEnoughMoney(jsonrpc.BaseError):
CODE = 6001
MESSAGE = 'Not enough money'
class DataModel(BaseModel):
balance: int
currency: str
Class attributes¶
CODE: int— JSON-RPC error code. Required.MESSAGE: str— human-readable message. Required.DataModel: type[BaseModel] | None— optional Pydantic model for theerror.datapayload. When set, the value passed toraise MyError(data=...)is validated against it.ErrorModel: type[BaseModel] | None— optional model for entries insideerror.data.errors(used byInvalidRequestandInvalidParamsto describe individual validation issues).data_required: bool— ifTrue, thedatafield is required in the generated schema. Default:False.errors_required: bool— same, but for theerrorslist insidedata. Default:False.
Instance API¶
__init__(data=None)— creates the error;datais validated throughDataModelif one is set.get_resp() -> dict— builds the full JSON-RPC response dict ({jsonrpc, id, error}).get_resp_data()— returns the payload forerror.data.
Built-in errors¶
fastapi_jsonrpc exports the standard JSON-RPC 2.0 errors:
| Class | Code | Meaning |
|---|---|---|
ParseError |
-32700 | Invalid JSON was received |
InvalidRequest |
-32600 | The JSON sent is not a valid Request object |
MethodNotFound |
-32601 | The method does not exist / is not available |
InvalidParams |
-32602 | Invalid method parameter(s) |
InternalError |
-32603 | Internal JSON-RPC error |
Any unhandled exception raised from a method becomes an InternalError and is logged via Python's logging module.