[英]How do I set up email alerts for 500 errors using Flask?
I am using flask, marshmallow, and sql alchemy to make an API.我正在使用 flask、棉花糖和 sql 炼金术来制作 API。 I want to configure email alerts on 500 errors.
我想在 500 错误时配置 email 警报。 The other error types I have the email alerts for work fine.
其他错误类型我有 email 警报可以正常工作。
Error Handling Code错误处理代码
@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()
Function called in the 500 error handler: Function 在 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()
I suspect the e == 500
condition always evaluates to False
even in case of 500 error.我怀疑
e == 500
条件总是评估为False
即使在 500 错误的情况下。
You could fix it, but why not remove it?你可以修复它,但为什么不删除它? What's the purpose of this test if you decorate the handler with
@app.errorhandler(500)
?如果你用
@app.errorhandler(500)
装饰处理程序,这个测试的目的是什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.