]> de.git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Return proper HTTP codes.
authorAnt Zucaro <azucaro@gmail.com>
Wed, 7 Dec 2011 12:04:33 +0000 (07:04 -0500)
committerAnt Zucaro <azucaro@gmail.com>
Wed, 7 Dec 2011 12:04:33 +0000 (07:04 -0500)
The Pyramid documentation isn't very clear when it comes to HTTP
exceptions. They mention that one can either be raised or returned, but
in practice I'm only seeing error code 500 when I raise them. By adding
a textual description to the exception and returning them in the
exception handler (rather than just raise them again), the code seems to
work fine again.

xonstat/views/submission.py

index 09c0bb6156bdaa061d626410d22b8fc67f283e6d..d610e42f8fc367df50f4de976a4b33ba31e4fce4 100755 (executable)
@@ -505,39 +505,34 @@ def stats_submit(request):
 \r
         (idfp, status) = verify_request(request)\r
         if not idfp:\r
-            raise pyramid.httpexceptions.HTTPUnauthorized\r
-\r
-        log.debug('Remote address:')\r
-        log.debug(get_remote_addr(request))\r
+            log.debug("ERROR: Unverified request")\r
+            raise pyramid.httpexceptions.HTTPUnauthorized("Unverified request")\r
 \r
         (game_meta, players) = parse_body(request)  \r
 \r
         if not has_required_metadata(game_meta):\r
-            log.debug("Required game meta fields missing. "\\r
-                    "Can't continue.")\r
-            raise pyramid.exceptions.HTTPUnprocessableEntity\r
+            log.debug("ERROR: Required game meta missing")\r
+            raise pyramid.exceptions.HTTPUnprocessableEntity("Missing game meta")\r
 \r
         if not is_supported_gametype(game_meta['G']):\r
-            raise pyramid.httpexceptions.HTTPOk\r
+            log.debug("ERROR: Unsupported gametype")\r
+            raise pyramid.httpexceptions.HTTPOk("OK")\r
 \r
         if not has_minimum_real_players(request.registry.settings, players):\r
-            log.debug("The number of real players is below the minimum. " + \r
-                "Stats will be ignored.")\r
-            raise pyramid.httpexceptions.HTTPOk\r
+            log.debug("ERROR: Not enough real players")\r
+            raise pyramid.httpexceptions.HTTPOk("OK")\r
 \r
         server = get_or_create_server(session=session, hashkey=idfp, \r
                 name=game_meta['S'], revision=game_meta['R'],\r
                 ip_addr=get_remote_addr(request))\r
 \r
         gmap = get_or_create_map(session=session, name=game_meta['M'])\r
-        log.debug(gmap)\r
 \r
         game = create_game(session=session, \r
                 start_dt=datetime.datetime(\r
                     *time.gmtime(float(game_meta['T']))[:6]), \r
                 server_id=server.server_id, game_type_cd=game_meta['G'], \r
                    map_id=gmap.map_id, match_id=game_meta['I'])\r
-        log.debug(gmap)\r
 \r
         # find or create a record for each player\r
         # and add stats for each if they were present at the end\r
@@ -561,4 +556,4 @@ def stats_submit(request):
         return Response('200 OK')\r
     except Exception as e:\r
         session.rollback()\r
-        raise e\r
+        return e\r