【发布时间】:2019-10-23 19:42:14
【问题描述】:
我正在使用烧瓶、棉花糖和 sql alchemy 来制作 API。我想针对 500 个错误配置电子邮件警报。其他错误类型我有工作正常的电子邮件警报。
错误处理代码
@app.errorhandler(ValidationError)
def handle_marshmallow_validation(err): # except ValidationError as err
return jsonify(err.messages), 400
@app.errorhandler(500)
def server_error(e):
if e == 500:
error_500_email()
在 500 错误处理程序中调用的函数:
def error_500_email():
s = smtplib.SMTP(host='mailo2.uhc.com', port=25)
text = "There was an error"
msg = MIMEText(str(text))
msg['Subject'] = 'Prod SA Tool Error'
s.sendmail('sa_prod@optum.com', 'ian.christ@optum.com', msg.as_string())
s.quit()
【问题讨论】:
-
这与棉花糖无关。但作为旁注,我会在棉花糖错误上返回 422。考虑使用 webargs 为您执行此操作。
标签: python python-3.x api flask-sqlalchemy marshmallow