]> de.git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Return different HTTP status codes based on what happened.
authorAnt Zucaro <azucaro@gmail.com>
Tue, 1 Nov 2011 16:57:03 +0000 (12:57 -0400)
committerAnt Zucaro <azucaro@gmail.com>
Tue, 1 Nov 2011 16:57:03 +0000 (12:57 -0400)
xonstat/views/submission.py

index 74466edb4ebfcdb13787294c672ac2d4cf066d05..ea3e5c1a37f5f74b07ea3d83161f0533529b99eb 100755 (executable)
@@ -1,5 +1,6 @@
 import datetime\r
 import logging\r
+import pyramid.httpexceptions\r
 import re\r
 import time\r
 from pyramid.config import get_current_registry\r
@@ -22,12 +23,16 @@ def is_supported_gametype(gametype):
 \r
 \r
 def verify_request(request):\r
-    (idfp, status) = d0_blind_id_verify(\r
-            sig=request.headers['X-D0-Blind-Id-Detached-Signature'],\r
-            querystring='',\r
-            postdata=request.body)\r
+    try:\r
+        (idfp, status) = d0_blind_id_verify(\r
+                sig=request.headers['X-D0-Blind-Id-Detached-Signature'],\r
+                querystring='',\r
+                postdata=request.body)\r
 \r
-    log.debug('\nidfp: {0}\nstatus: {1}'.format(idfp, status))\r
+        log.debug('\nidfp: {0}\nstatus: {1}'.format(idfp, status))\r
+    except: \r
+        idfp = None\r
+        status = None\r
 \r
     return (idfp, status)\r
 \r
@@ -464,21 +469,22 @@ def stats_submit(request):
 \r
         (idfp, status) = verify_request(request)\r
         if not idfp:\r
-            raise Exception("Request is not verified.")\r
+            raise pyramid.httpexceptions.HTTPUnauthorized\r
 \r
         (game_meta, players) = parse_body(request)  \r
     \r
         if not has_required_metadata(game_meta):\r
-            log.debug("Required game meta fields (T, G, M, or S) missing. "\\r
+            log.debug("Required game meta fields missing. "\\r
                     "Can't continue.")\r
-            raise Exception("Required game meta fields (T, G, M, or S) missing.")\r
+            raise pyramid.exceptions.HTTPUnprocessableEntity\r
    \r
         if not is_supported_gametype(game_meta['G']):\r
-            raise Exception("Gametype not supported.")\r
+            raise pyramid.httpexceptions.HTTPOk\r
      \r
         if not has_minimum_real_players(players):\r
-            raise Exception("The number of real players is below the minimum. "\\r
-                    "Stats will be ignored.")\r
+            log.debug("The number of real players is below the minimum. " + \r
+                "Stats will be ignored.")\r
+            raise pyramid.httpexceptions.HTTPOk\r
 \r
         server = get_or_create_server(session=session, hashkey=idfp, \r
                 name=game_meta['S'])\r