diff --git a/error_tracker/__init__.py b/error_tracker/__init__.py index d2f1205..9fd5b5f 100644 --- a/error_tracker/__init__.py +++ b/error_tracker/__init__.py @@ -6,27 +6,37 @@ # :license: BSD-3-Clause # -__version__ = '1.1.7' +__version__ = '1.1.8' __author__ = 'Sonu Kumar' __email__ = 'sonunitw12@gmail.com' from error_tracker.libs.mixins import * +from error_tracker.libs.exception_formatter import * +flaskInstalled = False try: import flask - from error_tracker.flask import * - from error_tracker.flask.utils import configure_scope as flask_scope + + flaskInstalled = True except ImportError: pass + +if flaskInstalled: + from error_tracker.flask import * + from error_tracker.flask.utils import configure_scope as flask_scope + +djangoInstalled = False try: import django + + djangoInstalled = True +except ImportError as e: + raise e + +if djangoInstalled: from error_tracker.django import * from error_tracker.django.apps import DjangoErrorTracker from error_tracker.django.utils import capture_message, track_exception, configure_scope, capture_exception -except ImportError: - pass - -from error_tracker.libs.exception_formatter import * __all__ = [ # flask modules diff --git a/error_tracker/django/migrations/0002_auto_20201018_1311.py b/error_tracker/django/migrations/0002_auto_20201018_1311.py index 829f2b8..a427d28 100644 --- a/error_tracker/django/migrations/0002_auto_20201018_1311.py +++ b/error_tracker/django/migrations/0002_auto_20201018_1311.py @@ -6,7 +6,7 @@ class Migration(migrations.Migration): dependencies = [ - ('django', '0001_initial'), + ('error_tracker', '0001_initial'), ] operations = [ diff --git a/error_tracker/django/utils.py b/error_tracker/django/utils.py index 21c9f68..8fbe6c3 100644 --- a/error_tracker/django/utils.py +++ b/error_tracker/django/utils.py @@ -9,7 +9,6 @@ import re import json from django.http import RawPostDataException -from http.cookies import SimpleCookie from error_tracker.libs.mixins import ContextBuilderMixin, NotificationMixin, ViewPermissionMixin from error_tracker.libs.utils import get_context_dict @@ -91,6 +90,7 @@ def notify(self, request, exception, exception.notification_sent = True exception.save() + class DefaultDjangoViewPermission(ViewPermissionMixin): def __call__(self, request): @@ -190,6 +190,27 @@ def clean_value(x): return x +def get_value(key, value): + try: + # Parse each key, value from headers items and Test if could be "json loaded". If not, we set the correspondant value to empty except for cookie key. + json.loads('{"%s":"%s"}' % (key, value)) + except Exception as e: + if key in ["Cookie", "cookie"]: + try: + from http.cookies import SimpleCookie + try: + cookie = SimpleCookie() + cookie.load(value) + value = {k: clean_value(v) for k, v in cookie.items()} + except Exception as e: + value = "" + except ImportError: + pass + else: + value = "" + return value + + def parse_headers(headers): """ Parse request headers to extract cookie. @@ -198,19 +219,5 @@ def parse_headers(headers): """ new_headers = {} for key, value in headers.items(): - try: - # Pare each key, value from headers items and Test if could be "json loaded". If not, we set the correspondant value to empty except for cookie key. - json.loads('{"%s":"%s"}' % (key, value)) - except Exception as e: - if key in ["Cookie", "cookie"]: - try: - cookie = SimpleCookie() - cookie.load(value) - value = {k: clean_value(v) for k, v in cookie.items()} - except Exception as e: - value = "" - else: - value = "" - - new_headers[key] = value + new_headers[key] = get_value(key, value) return new_headers