From 40500d46b8a9724a54dc4be6be027d49aa610b56 Mon Sep 17 00:00:00 2001 From: Ernst Widerberg Date: Fri, 15 Oct 2021 14:44:17 +0200 Subject: Update ObjectView getData --- src/components/ObjectView.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/components/ObjectView.js b/src/components/ObjectView.js index 08951c0..3b39c96 100644 --- a/src/components/ObjectView.js +++ b/src/components/ObjectView.js @@ -22,14 +22,22 @@ class ObjectView 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.data; + 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({ + object: json.data + }); }) - .then(object => this.setState({ object: object })) .catch(e => this.props.setError(e)); } -- cgit v1.1