Mikhail Korobov avatar Mikhail Korobov committed ae2a48b

Some logging

Comments (0)

Files changed (2)

 #coding: utf-8
+import logging
+
 from django.http import HttpResponse, Http404
 from django.views.generic.simple import direct_to_template
 from django.shortcuts import get_object_or_404
 from netcash import signals
 from netcash.conf import NETCASH_IP_HEADER
 
+# setup logging
+class NullHandler(logging.Handler):
+    def emit(self, record):
+        pass
+logging.getLogger("netcash").addHandler(NullHandler())
+
 @csrf_exempt
 def data_handler(request, secret):
     """
     On successful access 'netcash.signals.data' signal is sent.
     Orders should be processed in signal handler.
     """
-    gateway = get_object_or_404(NetcashGateway, secret=secret)
+
+    logger = logging.getLogger("netcash")
+
+    try:
+        gateway = NetcashGateway.objects.get(secret=secret)
+    except NetcashGateway.DoesNotExist:
+        logger.warn('Invalid gateway %s. Request: %s', secret, request.raw_post_data)
+        raise Http404
+
     ip = request.META.get(NETCASH_IP_HEADER, None)
     reference = request.POST.get('Reference', None)
-    order = get_object_or_404(NetcashOrder, pk=reference)
+
+    try:
+        order = NetcashOrder.objects.get(pk=reference)
+    except NetcashOrder.DoesNotExist:
+        logger.warn('Unknown order %s. Request: %s', reference, request.raw_post_data)
+        raise Http404
 
     if order.trusted: # don't process processed orders again
+        logger.warn('Order %s is already processed. Request: %s',
+                    order.pk, request.raw_post_data)
         raise Http404
 
     if gateway.netcash_ip:
 
 setup(
     name='django-netcash',
-    version='0.4.0',
+    version='0.4.1',
     author='Mikhail Korobov',
     author_email='kmike84@gmail.com',
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.