Add api error handling while creating an account
This commit is contained in:
parent
d5f014b3d5
commit
e1a421c9c2
@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<b-card class="mt-3" header="Signup">
|
<b-card class="mt-3" header="Create an account">
|
||||||
<b-form @submit.prevent="handleSubmit">
|
<b-form @submit.prevent="handleSubmit">
|
||||||
<b-form-group
|
<b-form-group
|
||||||
id="email-group"
|
id="email-group"
|
||||||
@ -60,6 +60,14 @@
|
|||||||
|
|
||||||
<b-button type="submit" variant="primary">Submit</b-button>
|
<b-button type="submit" variant="primary">Submit</b-button>
|
||||||
</b-form>
|
</b-form>
|
||||||
|
|
||||||
|
<b-alert :show="exists" variant="danger" dismissible class="mt-3">
|
||||||
|
A user with that username or email already exists
|
||||||
|
</b-alert>
|
||||||
|
<b-alert :show="error" variant="danger" dismissible class="mt-3">
|
||||||
|
An error occurred while attempting to create your account
|
||||||
|
</b-alert>
|
||||||
|
|
||||||
</b-card>
|
</b-card>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -77,6 +85,8 @@
|
|||||||
password: '',
|
password: '',
|
||||||
passwordConfirm: ''
|
passwordConfirm: ''
|
||||||
},
|
},
|
||||||
|
error: false,
|
||||||
|
exists: false,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -96,6 +106,8 @@
|
|||||||
methods: {
|
methods: {
|
||||||
handleSubmit() {
|
handleSubmit() {
|
||||||
if (this.validInput) {
|
if (this.validInput) {
|
||||||
|
this.error = false
|
||||||
|
this.exists = false
|
||||||
this.signup()
|
this.signup()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -104,7 +116,14 @@
|
|||||||
username: this.form.username,
|
username: this.form.username,
|
||||||
email: this.form.email,
|
email: this.form.email,
|
||||||
password: this.form.password
|
password: this.form.password
|
||||||
}).then(response => console.log(response.data))
|
})
|
||||||
|
.then(response => console.log(response.data))
|
||||||
|
.catch(error => {
|
||||||
|
if (error.response && error.response.status === 409)
|
||||||
|
this.exists = true
|
||||||
|
else
|
||||||
|
this.error = true
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user