diff options
-rw-r--r-- | src/components/List.js | 8 | ||||
-rw-r--r-- | src/components/Login.js | 23 | ||||
-rw-r--r-- | src/components/ObjectView.js | 8 |
3 files changed, 23 insertions, 16 deletions
diff --git a/src/components/List.js b/src/components/List.js index 0bf359b..e526c4b 100644 --- a/src/components/List.js +++ b/src/components/List.js @@ -60,7 +60,9 @@ class List extends React.Component { // TODO: Look at `status` or return code or both? .then(resp => { if (resp.status !== 200) - throw `Unexpected HTTP response code from soc_collector: ${resp.status} ${resp.statusText}`; + throw new Error( + `Unexpected HTTP response code from soc_collector: ${resp.status} ${resp.statusText}` + ); this.setState({ totalPages: parseInt(resp.headers.get("X-Total-Count")) }); @@ -68,7 +70,9 @@ class List extends React.Component { }) .then(json => { if (json.status != "success") - throw `Unexpected status from soc_collector: ${json.status}`; + throw new Error( + `Unexpected status from soc_collector: ${json.status}` + ); this.setState({ objects: json.docs }); diff --git a/src/components/Login.js b/src/components/Login.js index 6379386..4339539 100644 --- a/src/components/Login.js +++ b/src/components/Login.js @@ -17,7 +17,7 @@ class Login extends React.Component { this.state = { email: "", password: "", - error: false + loginFailed: false }; this.login = this.login.bind(this); @@ -31,21 +31,20 @@ class Login extends React.Component { headers: { Authorization: "Basic " + btoa(email + ":" + password) } }) .then(resp => { - if (resp.status !== 200) throw resp; + if (resp.status === 401) { + // Unauthorized: Wrong email/password + this.setState({ loginFailed: true }); + return; + } + if (resp.status !== 200) + throw new Error( + `Unexpected HTTP response code from JWT server: ${resp.status} ${resp.statusText}` + ); return resp; }) .then(resp => resp.json()) .then(data => { this.props.setToken(data.access_token); - }) - .catch(resp => { - if (resp.status === 401) this.setState({ error: true }); - else - this.props.setError( - new Error( - `Unexpected response status: ${resp.status} ${resp.statusText}` - ) - ); }); } @@ -106,7 +105,7 @@ class Login extends React.Component { > Sign in </Button> - {this.state.error && ( + {this.state.loginFailed && ( <p className="error">Wrong username or password</p> )} </Paper> diff --git a/src/components/ObjectView.js b/src/components/ObjectView.js index cecadeb..72c7e5c 100644 --- a/src/components/ObjectView.js +++ b/src/components/ObjectView.js @@ -25,7 +25,9 @@ class ObjectView extends React.Component { // TODO: Look at `status` or return code or both? .then(resp => { if (resp.status !== 200) - throw `Unexpected HTTP response code from soc_collector: ${resp.status} ${resp.statusText}`; + throw new Error( + `Unexpected HTTP response code from soc_collector: ${resp.status} ${resp.statusText}` + ); this.setState({ totalPages: resp.headers.get("X-Total-Count") }); @@ -33,7 +35,9 @@ class ObjectView extends React.Component { }) .then(json => { if (json.status != "success") - throw `Unexpected status from soc_collector: ${json.status}`; + throw new Error( + `Unexpected status from soc_collector: ${json.status}` + ); this.setState({ object: json.docs }); |