def set_status(id): status_started = status_timer.start_timer() customer = g.get('customer', None) try: alert = db.get_alert(id=id, customer=customer) except Exception as e: status_timer.stop_timer(status_started) return jsonify(status="error", message=str(e)), 500 if not alert: status_timer.stop_timer(status_started) return jsonify(status="error", message="not found", total=0, alert=None), 404 status = request.json.get('status', None) text = request.json.get('text', '') if not status: status_timer.stop_timer(status_started) return jsonify(status="error", message="must supply 'status' as parameter"), 400 try: process_status(alert, status, text) except RejectException as e: status_timer.stop_timer(status_started) return jsonify(status="error", message=str(e)), 403 except Exception as e: status_timer.stop_timer(status_started) return jsonify(status="error", message=str(e)), 500 try: alert = db.set_status(id=id, status=status, text=text) except Exception as e: status_timer.stop_timer(status_started) return jsonify(status="error", message=str(e)), 500 if alert: status_timer.stop_timer(status_started) return jsonify(status="ok") else: status_timer.stop_timer(status_started) return jsonify(status="error", message="not found"), 404