Wpis z mikrobloga

Zaczelam bawic sie Pythonem i stworzylem proste API - kalkulator wyplat. Pytanie jest jak najlpiej lapac wszystkie bledy? Np. request nie jest w formacie JSON, albo zapytanie idzie na niewlasciwa 'route'? Obecnie wyglada to tak, ale nie wiem czy tak to powinno sie robic:

@app.route('/salary', methods=['POST'])
def salary():
if request.isjson:
if "salary" in request.json:
salary
post = request.json
aftertax = (final-incometax-nationalinsurance) / 12
return jsonify({"Your monthly salary after tax" : round(after
tax)})
else:
return jsonify({"error": "Invalid request"}), 400
else:
return jsonify({"error": "We only accept JSON"}), 400

#python
  • 4