Add "bad values" error
This commit is contained in:
parent
4d610c5bff
commit
05d22a0ce8
|
@ -1,3 +1,4 @@
|
||||||
_400 = {"error": "insufficient parameters"}
|
_400 = {"error": "insufficient parameters"}
|
||||||
|
_400_bv = {"error": "bad values"}
|
||||||
_401 = {"error": "invalid token"}
|
_401 = {"error": "invalid token"}
|
||||||
_404 = {"error": "The quest/side quest doesn't exist"}
|
_404 = {"error": "The quest/side quest doesn't exist"}
|
||||||
|
|
24
server.py
24
server.py
|
@ -149,10 +149,10 @@ def add_quest(db):
|
||||||
except (KeyError):
|
except (KeyError):
|
||||||
return jsonify(errors._400), 400
|
return jsonify(errors._400), 400
|
||||||
except (ValueError):
|
except (ValueError):
|
||||||
return jsonify(errors._400), 400
|
return jsonify(errors._400_bv), 400
|
||||||
|
|
||||||
if imp not in [1, 2, 3] or diff not in [1, 2, 3]:
|
if imp not in [1, 2, 3] or diff not in [1, 2, 3]:
|
||||||
return jsonify(errors._400), 400
|
return jsonify(errors._400_bv), 400
|
||||||
|
|
||||||
quest = questable.add_quest(db, player.CHAT_ID, qid, name, imp, diff, 0)
|
quest = questable.add_quest(db, player.CHAT_ID, qid, name, imp, diff, 0)
|
||||||
return jsonify(dictify_quest(quest))
|
return jsonify(dictify_quest(quest))
|
||||||
|
@ -182,10 +182,10 @@ def add_side_quest(db):
|
||||||
except (KeyError):
|
except (KeyError):
|
||||||
return jsonify(errors._400), 400
|
return jsonify(errors._400), 400
|
||||||
except (ValueError):
|
except (ValueError):
|
||||||
return jsonify(errors._400), 400
|
return jsonify(errors._400_bv), 400
|
||||||
|
|
||||||
if imp not in [1, 2, 3] or diff not in [1, 2, 3]:
|
if imp not in [1, 2, 3] or diff not in [1, 2, 3]:
|
||||||
return jsonify(errors._400), 400
|
return jsonify(errors._400_bv), 400
|
||||||
|
|
||||||
quest = questable.add_side_quest(db, player.CHAT_ID, qid, name, imp,
|
quest = questable.add_side_quest(db, player.CHAT_ID, qid, name, imp,
|
||||||
diff, 0)
|
diff, 0)
|
||||||
|
@ -227,13 +227,13 @@ def update_quest(db):
|
||||||
if diff in [1, 2, 3]:
|
if diff in [1, 2, 3]:
|
||||||
quest.diff = diff
|
quest.diff = diff
|
||||||
else:
|
else:
|
||||||
return jsonify(errors._400), 400
|
return jsonify(errors._400_bv), 400
|
||||||
elif i == "priority":
|
elif i == "priority":
|
||||||
imp = int(request.values["priority"])
|
imp = int(request.values["priority"])
|
||||||
if imp in [1, 2, 3]:
|
if imp in [1, 2, 3]:
|
||||||
quest.imp = imp
|
quest.imp = imp
|
||||||
else:
|
else:
|
||||||
return jsonify(errors._400), 400
|
return jsonify(errors._400_bv), 400
|
||||||
elif i == "state":
|
elif i == "state":
|
||||||
state = bool(request.values["state"])
|
state = bool(request.values["state"])
|
||||||
if state is True:
|
if state is True:
|
||||||
|
@ -241,9 +241,9 @@ def update_quest(db):
|
||||||
points = 55 + 10*quest.imp + 15*quest.diff
|
points = 55 + 10*quest.imp + 15*quest.diff
|
||||||
player.add_points(points)
|
player.add_points(points)
|
||||||
else:
|
else:
|
||||||
return jsonify(errors._400), 400
|
return jsonify(errors._400_bv), 400
|
||||||
except (ValueError):
|
except (ValueError):
|
||||||
return jsonify(errors._400), 400
|
return jsonify(errors._400_bv), 400
|
||||||
|
|
||||||
quest.update_db()
|
quest.update_db()
|
||||||
return jsonify(dictify_quest(quest))
|
return jsonify(dictify_quest(quest))
|
||||||
|
@ -284,13 +284,13 @@ def update_side_quest(db):
|
||||||
if diff in [1, 2, 3]:
|
if diff in [1, 2, 3]:
|
||||||
quest.diff = diff
|
quest.diff = diff
|
||||||
else:
|
else:
|
||||||
return jsonify(errors._400), 400
|
return jsonify(errors._400_bv), 400
|
||||||
elif i == "priority":
|
elif i == "priority":
|
||||||
imp = int(request.values["priority"])
|
imp = int(request.values["priority"])
|
||||||
if imp in [1, 2, 3]:
|
if imp in [1, 2, 3]:
|
||||||
quest.imp = imp
|
quest.imp = imp
|
||||||
else:
|
else:
|
||||||
return jsonify(errors._400), 400
|
return jsonify(errors._400_bv), 400
|
||||||
elif i == "state":
|
elif i == "state":
|
||||||
state = bool(request.values["state"])
|
state = bool(request.values["state"])
|
||||||
if state is True:
|
if state is True:
|
||||||
|
@ -298,9 +298,9 @@ def update_side_quest(db):
|
||||||
points = 10*quest.imp + 15*quest.diff
|
points = 10*quest.imp + 15*quest.diff
|
||||||
player.add_points(points)
|
player.add_points(points)
|
||||||
else:
|
else:
|
||||||
return jsonify(errors._400), 400
|
return jsonify(errors._400_bv), 400
|
||||||
except (ValueError):
|
except (ValueError):
|
||||||
return jsonify(errors._400), 400
|
return jsonify(errors._400_bv), 400
|
||||||
|
|
||||||
quest.update_db()
|
quest.update_db()
|
||||||
return jsonify(dictify_quest(quest))
|
return jsonify(dictify_quest(quest))
|
||||||
|
|
Loading…
Reference in New Issue