From 55c01035fe06e58f28daa161c6e85261501b560e Mon Sep 17 00:00:00 2001 From: britea Date: Wed, 4 Mar 2020 18:49:56 +0100 Subject: [PATCH] Added Error handling on Login Page --- smart-hut/src/App.js | 2 ++ smart-hut/src/client_server.js | 2 +- smart-hut/src/views/Login.js | 23 +++++++++++++---------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/smart-hut/src/App.js b/smart-hut/src/App.js index 56c3095..fd6ccee 100644 --- a/smart-hut/src/App.js +++ b/smart-hut/src/App.js @@ -73,9 +73,11 @@ class App extends React.Component { this.setState({ error: res.data.message }); + return this.state.error; } }).catch(err => { console.log(err); + return {status : "Errore"}; }); }; diff --git a/smart-hut/src/client_server.js b/smart-hut/src/client_server.js index 1d61886..879d53d 100644 --- a/smart-hut/src/client_server.js +++ b/smart-hut/src/client_server.js @@ -8,7 +8,7 @@ export var call = { .then(res => { return res; }).catch(err => { - console.error(err); + return err; }); }, register: function(data, headers) { diff --git a/smart-hut/src/views/Login.js b/smart-hut/src/views/Login.js index 4650666..3e406a0 100644 --- a/smart-hut/src/views/Login.js +++ b/smart-hut/src/views/Login.js @@ -8,6 +8,8 @@ export default class Login extends Component { user: "", password : "", fireRedirect: false, + error : {state : false, + message: ""}, }; } @@ -23,10 +25,9 @@ export default class Login extends Component { user: this.state.user, params : params, }).then(res => { - if (res === '400') { - console.log('error'); - } else { - console.log("SUCCESS"); + if (res.status === "Errore") { + this.setState({error: {state: true, + message: "Errore"}}); } }).catch(err => { console.log(err); @@ -51,13 +52,19 @@ export default class Login extends Component { href="/" > - Go Home + Go Home +
Log-in to SmartHut
-
+ +