Skip to content

Commit

Permalink
Handle error when trying to save URL
Browse files Browse the repository at this point in the history
  • Loading branch information
Relequestual committed Jan 3, 2020
1 parent 31479b8 commit 821d295
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<save-button
:schema="primarySchemaText"
:instance="instanceText"
@error="handleError"
/>
</template>
</navigation>
Expand All @@ -19,7 +20,7 @@

<b-row v-if="errorMessage !== null" align-h="center">
<b-col>
<b-alert variant="danger" show dismissible>
<b-alert variant="danger" show dismissible @dismissed="clearError">
{{ errorMessage }}
</b-alert>
</b-col>
Expand Down Expand Up @@ -311,6 +312,12 @@ export default {
updateEditorTheme: function(theme) {
Vue.set(this, 'editorTheme', theme);
},
handleError: function (error) {
Vue.set(this, 'errorMessage', error);
},
clearError: function() {
Vue.set(this, 'errorMessage', null);
}
},
};
</script>
Expand Down
13 changes: 9 additions & 4 deletions src/components/SaveButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,15 @@ export default {
methods: {
saveURLClick: async function() {
Vue.set(this, 'saving', true);
const url = await shorter.genSaveURL({ sharedSchema: this.schema, sharedInstance: this.instance});
const shortURL = await shorter.shortenURL(url);
this.$router.replace(`/s/${shortURL}`);
Vue.set(this, 'saved', true);
try{
const url = await shorter.genSaveURL({ sharedSchema: this.schema, sharedInstance: this.instance});
const shortURL = await shorter.shortenURL(url);
this.$router.replace(`/s/${shortURL}`);
Vue.set(this, 'saved', true);
} catch(e) {
this.resetData();
this.$emit('error', e.message);
}
},
resetData: function (){
const data = initialData();
Expand Down
3 changes: 3 additions & 0 deletions src/utilities/shortner.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const shortenURL = async (url) => {
}

const result = await shorten(url);
if(result.status === 'fail') {
throw new Error(`Unable to save URL - ${result.message}`);
}
return result.url.keyword;
}

Expand Down

0 comments on commit 821d295

Please sign in to comment.