有人知道哨兵如何拦截异常吗?
我只是开始使用Sentry。这是给我的建议:
// add this
const Sentry = require('@sentry/node');
Sentry.init({ dsn: 'https://eed343acxxxxxxxxxxx3bb7e3f4bc10@sentry.io/1511416' });
// and call some undefined function
myUndefinedFunction();
因此,如果没有try .. catch
,Sentry如何跟踪错误?源代码是开放的,但很难掌握。
P.S。我对内部工作机制感兴趣,而不对用户说明感兴趣。
答案 0 :(得分:0)
如果有错误,应将错误发送给哨兵,如下所示:
def timestamp(request):
TodayStartdate = datetime.now().strftime("%Y-%m-%d") + " 00:00"
TodayEnddate = datetime.now().strftime("%Y-%m-%d") + " 23:59"
Timestamp = Attendance.objects.filter(reader_Timestamp__range=
(TodayStartdate, TodayEnddate))
Login = Timestamp.first()
Logout = Timestamp.last()
print(Login)
print(Logout)
return render(request, 'app/timestamp.html')
答案 1 :(得分:0)
您只需要添加captureExcepton:
Sentry.init({ dsn: 'https://8ad77012ba2c436aba8a12e0b6cfd46b@sentry.io/1382991' });
function captureError(err){
Sentry.withScope(scope => {
Object.keys(extra).forEach(key => { //Here you can add extra message(optional)
scope.setExtra(key, extra[key]);
});
Sentry.captureException(error); //important
});
}
and you can call this function from anywhere just pass err object
注意:您需要在函数或尝试捕获中捕获此错误。您需要告诉哨兵捕获此异常