From 165cc8f02a6921314b67f874d1b63d8018bca9a0 Mon Sep 17 00:00:00 2001 From: britea Date: Wed, 4 Mar 2020 21:24:18 +0100 Subject: [PATCH] Error handling Signup page --- smart-hut/src/client_server.js | 3 ++- smart-hut/src/views/Login.js | 8 ++++---- smart-hut/src/views/Signup.js | 20 +++++++++++++------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/smart-hut/src/client_server.js b/smart-hut/src/client_server.js index 879d53d..2ff993f 100644 --- a/smart-hut/src/client_server.js +++ b/smart-hut/src/client_server.js @@ -16,7 +16,8 @@ export var call = { .then(res => { return res; }).catch(err => { - console.error(err); + //console.error(err); + return {status : "Errore"}; }); }, }; diff --git a/smart-hut/src/views/Login.js b/smart-hut/src/views/Login.js index 3e406a0..5fd9e5e 100644 --- a/smart-hut/src/views/Login.js +++ b/smart-hut/src/views/Login.js @@ -8,8 +8,8 @@ export default class Login extends Component { user: "", password : "", fireRedirect: false, - error : {state : false, - message: ""}, + error : { state : false, + message: ""}, }; } @@ -26,8 +26,8 @@ export default class Login extends Component { params : params, }).then(res => { if (res.status === "Errore") { - this.setState({error: {state: true, - message: "Errore"}}); + this.setState({error: { state: true, + message: "Errore"}}); } }).catch(err => { console.log(err); diff --git a/smart-hut/src/views/Signup.js b/smart-hut/src/views/Signup.js index 06b96d7..3a4330d 100644 --- a/smart-hut/src/views/Signup.js +++ b/smart-hut/src/views/Signup.js @@ -1,5 +1,5 @@ import React, {Component} from 'react'; -import {Button, Form, Grid, Header, Image, Icon, Input} from 'semantic-ui-react'; +import {Button, Form, Grid, Header, Image, Icon, Input, Message} from 'semantic-ui-react'; import { call } from '../client_server'; @@ -12,6 +12,8 @@ export default class Signup extends Component{ username: "", email: "", password : "", + error : { state : false, + message: ""}, }; } @@ -26,13 +28,13 @@ export default class Signup extends Component{ call.register(params) .then(res => { - if (res.data && res.status === 200) { - console.log(res.data); + if (res.status === "Errore") { + this.setState({error: { state: true, + message: "Errore"}}); } }).catch(err => { - + //console.log(err); }); - console.log(this.state); }; onChangeHandler = (event) => { @@ -47,7 +49,6 @@ export default class Signup extends Component{