Added user.uid to ApiError and Sentry logging

This commit is contained in:
mike cullerton 2020-12-11 16:26:03 -05:00
parent 8ba1e90f9a
commit 856fe445b0
1 changed files with 10 additions and 1 deletions

View File

@ -4,6 +4,8 @@ from flask import g
from crc import ma, app from crc import ma, app
import sentry_sdk
class ApiError(Exception): class ApiError(Exception):
def __init__(self, code, message, status_code=400, def __init__(self, code, message, status_code=400,
@ -16,6 +18,13 @@ class ApiError(Exception):
self.file_name = file_name or "" # OPTIONAL: The file that caused the error. self.file_name = file_name or "" # OPTIONAL: The file that caused the error.
self.tag = tag or "" # OPTIONAL: The XML Tag that caused the issue. self.tag = tag or "" # OPTIONAL: The XML Tag that caused the issue.
self.task_data = task_data or "" # OPTIONAL: A snapshot of data connected to the task when error ocurred. self.task_data = task_data or "" # OPTIONAL: A snapshot of data connected to the task when error ocurred.
if hasattr(g,'user'):
user = g.user.uid
else:
user = 'Unknown'
self.task_user = user
# This is for sentry logging into Slack
sentry_sdk.set_context("User", {'user': user})
Exception.__init__(self, self.message) Exception.__init__(self, self.message)
@classmethod @classmethod
@ -59,7 +68,7 @@ class ApiError(Exception):
class ApiErrorSchema(ma.Schema): class ApiErrorSchema(ma.Schema):
class Meta: class Meta:
fields = ("code", "message", "workflow_name", "file_name", "task_name", "task_id", fields = ("code", "message", "workflow_name", "file_name", "task_name", "task_id",
"task_data") "task_data", "task_user")
@app.errorhandler(ApiError) @app.errorhandler(ApiError)