Skip to content

Commit

Permalink
Silence get_json exceptions when json is optional
Browse files Browse the repository at this point in the history
  • Loading branch information
exelotl committed Mar 11, 2023
1 parent d46c48e commit 2929ebd
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions flaskbb/management/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,9 @@ class DeleteUser(MethodView):

def post(self, user_id=None):
# ajax request
if request.get_json() is not None:
ids = request.get_json().get("ids")
json = request.get_json(silent=True)
if json is not None:
ids = json.get("ids")
if not ids:
return jsonify(
message="No ids provided.",
Expand Down Expand Up @@ -432,8 +433,9 @@ def post(self, user_id=None):
return redirect(url_for("management.overview"))

# ajax request
if request.get_json() is not None:
ids = request.get_json().get("ids")
json = request.get_json(silent=True)
if json is not None:
ids = json.get("ids")
if not ids:
return jsonify(
message="No ids provided.",
Expand Down Expand Up @@ -505,8 +507,9 @@ def post(self, user_id=None):
return redirect(url_for("management.overview"))

# ajax request
if request.get_json() is not None:
ids = request.get_json().get("ids")
json = request.get_json(silent=True)
if json is not None:
ids = json.get("ids")
if not ids:
return jsonify(
message="No ids provided.",
Expand Down Expand Up @@ -652,8 +655,9 @@ class DeleteGroup(MethodView):
]

def post(self, group_id=None):
if request.get_json() is not None:
ids = request.get_json().get("ids")
json = request.get_json(silent=True)
if json is not None:
ids = json.get("ids")
if not ids:
return jsonify(
message="No ids provided.",
Expand Down Expand Up @@ -1002,8 +1006,9 @@ class MarkReportRead(MethodView):
def post(self, report_id=None):

# AJAX request
if request.get_json() is not None:
ids = request.get_json().get("ids")
json = request.get_json(silent=True)
if json is not None:
ids = json.get("ids")
if not ids:
return jsonify(
message="No ids provided.",
Expand Down Expand Up @@ -1077,8 +1082,9 @@ class DeleteReport(MethodView):
]

def post(self, report_id=None):
if request.get_json() is not None:
ids = request.get_json().get("ids")
json = request.get_json(silent=True)
if json is not None:
ids = json.get("ids")
if not ids:
return jsonify(
message="No ids provided.",
Expand Down

0 comments on commit 2929ebd

Please sign in to comment.