Verified Commit 0bbb3cc4 authored by Kevin Morris's avatar Kevin Morris
Browse files

fix(FastAPI): rpc - include other fields with errors



PHP does this, we should persist the behavior here for
v=5.

Signed-off-by: Kevin Morris's avatarKevin Morris <kevr@0cost.org>
parent 06ec6388
......@@ -51,20 +51,28 @@ async def rpc(request: Request,
type: Optional[str] = Query(None),
arg: Optional[str] = Query(None),
args: Optional[List[str]] = Query(None, alias="arg[]")):
# Ensure valid version was passed
if v is None:
return {"error": "Please specify an API version."}
elif v != 5:
return {"error": "Invalid version specified."}
# Defaults for returned data
returned_data = {}
returned_data["version"] = v
returned_data["results"] = []
returned_data["resultcount"] = 0
returned_data["type"] = type
# Default the type field to "error", until we determine that
# we're not erroneous (below).
returned_data["type"] = "error"
# Ensure valid version was passed
if v is None:
returned_data["error"] = "Please specify an API version."
return returned_data
elif v != 5:
returned_data["error"] = "Invalid version specified."
return returned_data
else:
# We got past initial error cases; set the type to what
# the user gave us.
returned_data["type"] = type
# Take arguments from either 'args' or 'args[]' and put them into 'argument_list'.
argument_list = []
......
......@@ -323,7 +323,13 @@ def test_rpc_bad_type():
def test_rpc_bad_version():
# Define expected response.
expected_data = {'error': 'Invalid version specified.'}
expected_data = {
'version': 0,
'resultcount': 0,
'results': [],
'type': 'error',
'error': 'Invalid version specified.'
}
# Make dummy request.
response = make_request("/rpc/?v=0&type=info&arg=big-chungus")
......@@ -337,7 +343,13 @@ def test_rpc_bad_version():
def test_rpc_no_version():
# Define expected response.
expected_data = {'error': 'Please specify an API version.'}
expected_data = {
'version': None,
'resultcount': 0,
'results': [],
'type': 'error',
'error': 'Please specify an API version.'
}
# Make dummy request.
response = make_request("/rpc/?type=info&arg=big-chungus")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment