summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2019-03-09 09:55:21 +0200
committerLars Wirzenius <liw@liw.fi>2019-03-09 09:55:21 +0200
commitda23a56ebcc767a76a86ae42a1839221ab126119 (patch)
tree54c2a9a719f9c98b7af662bc1f8bfef3ae325206
parenta1613e514ef1c1db4ce03fa72defe065da73a3c3 (diff)
downloadeffi-reg-da23a56ebcc767a76a86ae42a1839221ab126119.tar.gz
Change: handle faked /status calls without crashing
-rwxr-xr-xeffiapi14
1 files 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')