]> de.git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Make precondition failures return plain-text.
authorAnt Zucaro <azucaro@gmail.com>
Mon, 14 Nov 2016 01:09:15 +0000 (20:09 -0500)
committerAnt Zucaro <azucaro@gmail.com>
Mon, 14 Nov 2016 01:09:15 +0000 (20:09 -0500)
These show up in the server admin's logs as HTML currently. Making them plain
text (which is, of course, how the server logs are formatted) makes them easier
to see and understand.

xonstat/views/submission.py

index 68b68a9dd07515d0f783f6a476394c034f4461f9..2be4a27c8a7bd7a4e233b17386ffe1a8ff204509 100644 (file)
@@ -175,26 +175,46 @@ def do_precondition_checks(request, game_meta, raw_players):
     """Precondition checks for ALL gametypes.
        These do not require a database connection."""
     if not has_required_metadata(game_meta):
-        log.debug("ERROR: Required game meta missing")
-        raise pyramid.httpexceptions.HTTPUnprocessableEntity("Missing game meta")
+        msg = "Missing required game metadata"
+        log.debug(msg)
+        raise pyramid.httpexceptions.HTTPUnprocessableEntity(
+            body=msg,
+            content_type="text/plain"
+        )
 
     try:
         version = int(game_meta['V'])
     except:
-        log.debug("ERROR: Required game meta invalid")
-        raise pyramid.httpexceptions.HTTPUnprocessableEntity("Invalid game meta")
+        msg = "Invalid or incorrect game metadata provided"
+        log.debug(msg)
+        raise pyramid.httpexceptions.HTTPUnprocessableEntity(
+            body=msg,
+            content_type="text/plain"
+        )
 
     if not is_supported_gametype(game_meta['G'], version):
-        log.debug("ERROR: Unsupported gametype")
-        raise pyramid.httpexceptions.HTTPOk("OK")
+        msg = "Unsupported game type ({})".format(game_meta['G'])
+        log.debug(msg)
+        raise pyramid.httpexceptions.HTTPOk(
+            body=msg,
+            content_type="text/plain"
+        )
 
     if not has_minimum_real_players(request.registry.settings, raw_players):
-        log.debug("ERROR: Not enough real players")
-        raise pyramid.httpexceptions.HTTPOk("OK")
+        msg = "Not enough real players"
+        log.debug(msg)
+        raise pyramid.httpexceptions.HTTPOk(
+            body=msg,
+            content_type="text/plain"
+        )
 
     if is_blank_game(game_meta['G'], raw_players):
-        log.debug("ERROR: Blank game")
-        raise pyramid.httpexceptions.HTTPOk("OK")
+        msg = "Blank game"
+        log.debug(msg)
+        raise pyramid.httpexceptions.HTTPOk(
+            body=msg,
+            content_type="text/plain"
+        )
 
 
 def is_real_player(events):