From da23a56ebcc767a76a86ae42a1839221ab126119 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 9 Mar 2019 09:55:21 +0200 Subject: Change: handle faked /status calls without crashing --- effiapi | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/effiapi b/effiapi index d092446..bb1af9e 100755 --- a/effiapi +++ b/effiapi @@ -95,13 +95,19 @@ class FakeHTTPAPI(HTTPAPI): raise NotImplementedError() def GET(self, url, headers=None, body=None): + logging.info( + 'FakeHTTPAPI.GET url=%r headers=%r body=%r', + url, headers, body) + if headers is None: + logging.warning('FakeHTTPAPI.GET: no resource id in headers') return FakeResponse(400, {}, 'Missing headers') - logging.debug('GET headers %r', headers) + rid = headers.get('Muck-Id') - logging.info('GET for %r', rid) if not rid: + logging.warning('FakeHTTPAPI.GET: empty resource id in headers') return FakeResponse(404, {}, 'No such member') + memb = self._memb[rid] headers = { 'Muck-Id': rid, @@ -146,7 +152,9 @@ class MuckAPI: def status(self): url = self.url('/status') r = self._httpapi.GET(url) - return r.json() + if r.ok: + return r.json() + return {'resources': 0} def show(self, rid): url = self.url('/res') -- cgit v1.2.1