def METHOD_NAME(self, rid, code, message, data=None):
    e = {
        "code": code,
        "message": message,
    }
    if data is not None:
        e["data"] = data
    body = {
        "jsonrpc": "2.0",
        "id": rid,
        "error": e,
    }
    self._send(body)