chiark / gitweb /
wip
[hippotat.git] / client
diff --git a/client b/client
index 644215456616fb2f4932af73dcf7ff44d09898a0..ec28fd07de6c0f84cc5d960721ddd6dfb7f794ef 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):
     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)
   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):
   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()
 
   global outstanding
   outstanding -= 1
   check_outbound()
 
-def asyncfailure(reason):
-  global outstanding
-  outstanding += 1
-  req_err(None, reason)
-
 def check_outbound():
   global outstanding
 
 def check_outbound():
   global outstanding
 
@@ -162,6 +168,8 @@ def check_outbound():
                         c.url,
                         twisted.web.client.Headers(hh),
                         producer)
                         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)))
     req.addTimeout(c.http_timeout, reactor)
     req.addCallback((lambda resp: req_ok(req, resp)))
     req.addErrback((lambda err: req_err(req, err)))