Added Error handling on Login Page

This commit is contained in:
britea 2020-03-04 18:49:56 +01:00
parent dfe403d608
commit 55c01035fe
3 changed files with 16 additions and 11 deletions

View file

@ -73,9 +73,11 @@ class App extends React.Component {
this.setState({ this.setState({
error: res.data.message error: res.data.message
}); });
return this.state.error;
} }
}).catch(err => { }).catch(err => {
console.log(err); console.log(err);
return {status : "Errore"};
}); });
}; };

View file

@ -8,7 +8,7 @@ export var call = {
.then(res => { .then(res => {
return res; return res;
}).catch(err => { }).catch(err => {
console.error(err); return err;
}); });
}, },
register: function(data, headers) { register: function(data, headers) {

View file

@ -8,6 +8,8 @@ export default class Login extends Component {
user: "", user: "",
password : "", password : "",
fireRedirect: false, fireRedirect: false,
error : {state : false,
message: ""},
}; };
} }
@ -23,10 +25,9 @@ export default class Login extends Component {
user: this.state.user, user: this.state.user,
params : params, params : params,
}).then(res => { }).then(res => {
if (res === '400') { if (res.status === "Errore") {
console.log('error'); this.setState({error: {state: true,
} else { message: "Errore"}});
console.log("SUCCESS");
} }
}).catch(err => { }).catch(err => {
console.log(err); console.log(err);
@ -51,13 +52,19 @@ export default class Login extends Component {
href="/" href="/"
> >
<Icon name='arrow alternate circle left'/> <Icon name='arrow alternate circle left'/>
Go Home </Button> Go Home
</Button>
<Grid textAlign='center' style={{height: '70vh'}} verticalAlign='middle'> <Grid textAlign='center' style={{height: '70vh'}} verticalAlign='middle'>
<Grid.Column style={{maxWidth: 450}}> <Grid.Column style={{maxWidth: 450}}>
<Header as='h2' color='blue' textAlign='center'> <Header as='h2' color='blue' textAlign='center'>
<Image src='img/logo.png'/> Log-in to SmartHut <Image src='img/logo.png'/> Log-in to SmartHut
</Header> </Header>
<Form size='large' style={{marginTop : "2em"}}> <Form size='large' style={{marginTop : "2em"}} error={this.state.error.state}>
<Message
error
header='Login Error'
content= {this.state.error.message}
/>
<Form.Input <Form.Input
control={Input} control={Input}
type="text" type="text"
@ -66,10 +73,6 @@ export default class Login extends Component {
iconPosition='left' iconPosition='left'
placeholder='Username or E-mail' placeholder='Username or E-mail'
onChange={this.onChangeHandler} onChange={this.onChangeHandler}
/*error={{
content: 'Please enter a valid email address',
pointing: 'below',
}}*/
/> />
<Form.Input <Form.Input
icon='lock' icon='lock'