From 46fc6263d0f93506927f572591e301f615186413 Mon Sep 17 00:00:00 2001 From: Ernst Widerberg Date: Fri, 15 Oct 2021 14:42:33 +0200 Subject: Use mock X-Total-Count header from soc_collector --- soc_collector | 2 +- src/components/List.js | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/soc_collector b/soc_collector index 97e5e6e..d09b9f8 160000 --- a/soc_collector +++ b/soc_collector @@ -1 +1 @@ -Subproject commit 97e5e6eb214778a2c4b6bd5d348bd0ee0a3bd8d4 +Subproject commit d09b9f8625426eaec3b533da40783666e947ce2d diff --git a/src/components/List.js b/src/components/List.js index 80222db..b463102 100644 --- a/src/components/List.js +++ b/src/components/List.js @@ -40,14 +40,22 @@ class List extends React.Component { Authorization: "Basic " + btoa("user1:pw1") } }) - .then(resp => resp.json()) + // TODO: Look at `status` or return code or both? .then(resp => { - // TODO: Look at `status` or return code or both? - if (resp.status != "success") - throw `soc_collector responded: ${resp.status}`; - return resp; + if (resp.status !== 200) + throw `Unexpected HTTP response code from soc_collector: ${resp.status} ${resp.statusText}`; + this.setState({ + totalPages: resp.headers.get("X-Total-Count") + }); + return resp.json(); + }) + .then(json => { + if (json.status != "success") + throw `Unexpected status from soc_collector: ${json.status}`; + this.setState({ + objects: json.data + }); }) - .then(resp => this.setState({ objects: resp.data })) .catch(e => this.props.setError(e)); } @@ -93,7 +101,7 @@ class List extends React.Component { -- cgit v1.1