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 --- src/components/List.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'src/components/List.js') 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