Remove catch blocks where possible

This commit is contained in:
Bubka 2020-01-27 14:55:30 +01:00
parent 59fe66710a
commit a1f5358e4a
3 changed files with 32 additions and 63 deletions

View File

@ -75,7 +75,7 @@
// we check if a user account already exists // we check if a user account already exists
const { data } = await this.axios.post('api/checkuser') const { data } = await this.axios.post('api/checkuser')
if( data.userCount > 0) { if( data.userCount > 0 ) {
this.errorMessage = this.$t('errors.already_one_user_registered') + ' ' + this.$t('errors.cannot_register_more_user') this.errorMessage = this.$t('errors.already_one_user_registered') + ' ' + this.$t('errors.cannot_register_more_user')
this.$router.push({ name: 'flooded' }); this.$router.push({ name: 'flooded' });
} }
@ -83,23 +83,20 @@
}, },
methods : { methods : {
handleSubmit(e) { async handleSubmit(e) {
e.preventDefault() e.preventDefault()
this.form.post('api/register') const { data } = await this.form.post('api/register')
.then(response => {
localStorage.setItem('user',response.data.message.name)
localStorage.setItem('jwt',response.data.message.token)
if (localStorage.getItem('jwt') != null){ if( this.form.errors.any() === false ) {
localStorage.setItem('user',data.message.name)
localStorage.setItem('jwt',data.message.token)
if (localStorage.getItem('jwt') != null) {
this.$router.push({name: 'accounts'}) this.$router.push({name: 'accounts'})
} }
}) }
.catch(error => {
if( error.response.status !== 422 ) {
this.$router.push({ name: 'genericError', params: { err: error.response } });
}
});
} }
}, },

View File

@ -109,19 +109,15 @@
methods: { methods: {
createAccount() { async createAccount() {
// set current temp icon as account icon // set current temp icon as account icon
this.form.icon = this.tempIcon this.form.icon = this.tempIcon
this.form.post('/api/twofaccounts') await this.form.post('/api/twofaccounts')
.then(response => {
if( this.form.errors.any() === false ) {
this.$router.push({name: 'accounts', params: { InitialEditMode: false }}); this.$router.push({name: 'accounts', params: { InitialEditMode: false }});
}) }
.catch(error => {
if( error.response.status !== 422 ) {
this.$router.push({ name: 'genericError', params: { err: error.response } });
}
});
}, },
@ -132,26 +128,18 @@
this.$router.push({name: 'accounts', params: { InitialEditMode: false }}); this.$router.push({name: 'accounts', params: { InitialEditMode: false }});
}, },
uploadQrcode(event) { async uploadQrcode(event) {
let imgdata = new FormData(); let imgdata = new FormData();
imgdata.append('qrcode', this.$refs.qrcodeInput.files[0]); imgdata.append('qrcode', this.$refs.qrcodeInput.files[0]);
this.form.upload('/api/qrcode/decode', imgdata) const { data } = await this.form.upload('/api/qrcode/decode', imgdata)
.then(response => {
this.form.service = response.data.service; this.form.fill(data)
this.form.account = response.data.account;
this.form.uri = response.data.uri;
})
.catch(error => {
if( error.response.status !== 422 ) {
this.$router.push({ name: 'genericError', params: { err: error.response } });
}
});
}, },
uploadIcon(event) { async uploadIcon(event) {
// clean possible already uploaded temp icon // clean possible already uploaded temp icon
this.deleteIcon() this.deleteIcon()
@ -159,15 +147,9 @@
let imgdata = new FormData(); let imgdata = new FormData();
imgdata.append('icon', this.$refs.iconInput.files[0]); imgdata.append('icon', this.$refs.iconInput.files[0]);
this.form.upload('/api/icon/upload', imgdata) const { data } = await this.form.upload('/api/icon/upload', imgdata)
.then(response => {
this.tempIcon = response.data; this.tempIcon = data;
})
.catch(error => {
if( error.response.status !== 422 ) {
this.$router.push({ name: 'genericError', params: { err: error.response } });
}
});
}, },

View File

@ -128,15 +128,11 @@
this.deleteIcon() this.deleteIcon()
} }
this.form.put('/api/twofaccounts/' + this.$route.params.twofaccountId) await this.form.put('/api/twofaccounts/' + this.$route.params.twofaccountId)
.then(response => {
this.$router.push({name: 'accounts', params: { InitialEditMode: true }}); if( this.form.errors.any() === false ) {
}) this.$router.push({name: 'accounts', params: { InitialEditMode: true }})
.catch(error => { }
if( error.response.status !== 422 ) {
this.$router.push({ name: 'genericError', params: { err: error.response } });
}
});
}, },
@ -147,7 +143,7 @@
this.$router.push({name: 'accounts', params: { InitialEditMode: true }}); this.$router.push({name: 'accounts', params: { InitialEditMode: true }});
}, },
uploadIcon(event) { async uploadIcon(event) {
// clean possible tempIcon but keep original one // clean possible tempIcon but keep original one
this.deleteIcon() this.deleteIcon()
@ -155,15 +151,9 @@
let imgdata = new FormData(); let imgdata = new FormData();
imgdata.append('icon', this.$refs.iconInput.files[0]); imgdata.append('icon', this.$refs.iconInput.files[0]);
this.form.upload('/api/icon/upload', imgdata) const { data } = await this.form.upload('/api/icon/upload', imgdata)
.then(response => {
this.tempIcon = response.data; this.tempIcon = data;
})
.catch(error => {
if( error.response.status !== 422 ) {
this.$router.push({ name: 'genericError', params: { err: error.response } });
}
});
}, },