diff options
author | Ernst Widerberg <ernstwi@kth.se> | 2021-10-15 14:42:33 +0200 |
---|---|---|
committer | Ernst Widerberg <ernstwi@kth.se> | 2021-10-15 14:42:33 +0200 |
commit | 46fc6263d0f93506927f572591e301f615186413 (patch) | |
tree | bab1563c340161dd5372d2eafc071da63893d181 /src/components/List.js | |
parent | d09d529677e42a0130b6188dfd2a90f6a6f06b0c (diff) |
Use mock X-Total-Count header from soc_collector
Diffstat (limited to 'src/components/List.js')
-rw-r--r-- | src/components/List.js | 22 |
1 files changed, 15 insertions, 7 deletions
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 { <Pagination activePage={this.state.page} // totalPages={this.totalPages()} - totalPages={5} // TODO + totalPages={this.state.totalPages} onPageChange={this.setPage} /> </div> |