chiark / gitweb /
wip
[hippotat.git] / client
diff --git a/client b/client
index 6442154..ec28fd0 100755 (executable)
--- a/client
+++ b/client
@@ -93,7 +93,17 @@ class ResponseConsumer(twisted.internet.protocol.Protocol):
     req_err(self._req, reason)
 
 def req_ok(req, resp):
-  log_debug(DBG.HTTP_CTRL, 'req_ok ' + str(resp), idof=req)
+  log_debug(DBG.HTTP_CTRL,
+            'req_ok %d %s %s' % (resp.code, repr(resp.phrase), str(resp)),
+            idof=req)
+  if resp.code != 200:
+    try:
+      phrase = resp.phrase.decode('utf-8')
+    except UnicodeDecodeError:
+      phrase = repr(resp.phrase)
+    req_err(req, "FAILED %d %s" % (resp.code, phrase))
+    return
+
   rc = ResponseConsumer(req)
   resp.deliverBody(rc)
   req_fin(req)
@@ -104,15 +114,11 @@ def req_err(req, err):
   reactor.callLater(c.http_retry, (lambda: req_fin(req)))
 
 def req_fin(req):
+  log_debug(DBG.HTTP_CTRL, 'req_fin', idof=req)
   global outstanding
   outstanding -= 1
   check_outbound()
 
-def asyncfailure(reason):
-  global outstanding
-  outstanding += 1
-  req_err(None, reason)
-
 def check_outbound():
   global outstanding
 
@@ -162,6 +168,8 @@ def check_outbound():
                         c.url,
                         twisted.web.client.Headers(hh),
                         producer)
+
+    log_debug(DBG.HTTP_CTRL, 'request', idof=req, d=d)
     req.addTimeout(c.http_timeout, reactor)
     req.addCallback((lambda resp: req_ok(req, resp)))
     req.addErrback((lambda err: req_err(req, err)))