mirror of
https://git.ikl.sh/132ikl/liteshort.git
synced 2023-08-10 21:13:04 +03:00
Fix non-API returning HTML despite Accept header
This commit is contained in:
parent
1062b71334
commit
fbb9a30eae
@ -135,13 +135,12 @@ def nested_list_to_dict(l):
|
|||||||
|
|
||||||
|
|
||||||
def response(rq, result, error_msg="Error: Unknown error"):
|
def response(rq, result, error_msg="Error: Unknown error"):
|
||||||
|
if rq.accept_mimetypes.accept_json and not rq.accept_mimetypes.accept_html:
|
||||||
|
if result:
|
||||||
|
return flask.jsonify(success=bool(result), result=result)
|
||||||
|
return flask.jsonify(success=bool(result), message=error_msg)
|
||||||
if rq.form.get("api"):
|
if rq.form.get("api"):
|
||||||
if rq.accept_mimetypes.accept_json:
|
return "Format type HTML (default) not supported for API" # Future-proof for non-json return types
|
||||||
if result:
|
|
||||||
return flask.jsonify(success=bool(result), result=result)
|
|
||||||
return flask.jsonify(success=bool(result), message=error_msg)
|
|
||||||
else:
|
|
||||||
return "Format type HTML (default) not supported for API" # Future-proof for non-json return types
|
|
||||||
else:
|
else:
|
||||||
if result and result is not True:
|
if result and result is not True:
|
||||||
flask.flash(result, "success")
|
flask.flash(result, "success")
|
||||||
|
Loading…
Reference in New Issue
Block a user