added try catch, added snackbar notification for errors returned (#10370)

* added try catch, added snackbar notification for errors returned

* moved lines into try block
This commit is contained in:
jerellmendoodoo 2018-05-18 11:04:18 -04:00 committed by Matteo Pagliazzi
parent 79087b27d3
commit 614848d60b

View file

@ -935,10 +935,22 @@
}
},
async feedAction (petKey, foodKey) {
const result = await this.$store.dispatch('common:feed', {pet: petKey, food: foodKey});
if (result.message) this.text(result.message);
if (this.user.preferences.suppressModals.raisePet) return;
if (this.user.items.pets[petKey] === -1) this.$root.$emit('habitica::mount-raised', petKey);
try {
const result = await this.$store.dispatch('common:feed', {pet: petKey, food: foodKey});
if (result.message) this.text(result.message);
if (this.user.preferences.suppressModals.raisePet) return;
if (this.user.items.pets[petKey] === -1) this.$root.$emit('habitica::mount-raised', petKey);
} catch (e) {
const errorMessage = e.message || e;
this.$store.dispatch('snackbars:add', {
title: 'Habitica',
text: errorMessage,
type: 'error',
timeout: true,
});
}
},
closeHatchPetDialog () {
this.$root.$emit('bv::hide::modal', 'hatching-modal');