From 23e250e165e98e80ee1b4280b3a5b8b34fcfbd3b Mon Sep 17 00:00:00 2001 From: Koki Oyatsu Date: Mon, 2 Dec 2019 16:11:37 +0900 Subject: [PATCH 1/2] Implement error handling for frontend. --- app/javascript/commons/custom-axios.js | 49 +++++++++++++++++++ .../components/backlogs/StoryModal.vue | 1 - .../components/kanban/TaskModal.vue | 1 - app/javascript/packs/backlogs.js | 2 + app/javascript/packs/closed_sprints.js | 2 + app/javascript/packs/kanban.js | 2 + app/javascript/packs/project_settings.js | 2 + .../ProjectSettings/GeneralSettingsPage.vue | 1 - app/javascript/stores/backlogs.js | 24 ++++----- app/javascript/stores/kanban.js | 28 +++++------ app/javascript/stores/project_settings.js | 12 +++-- .../stores/project_settings/generals.js | 13 ++--- .../project_settings/group_managements.js | 13 ++--- .../project_settings/ticket_categories.js | 16 ++---- .../project_settings/ticket_statuses.js | 18 +++---- app/javascript/stores/stories.js | 30 +++++------- app/javascript/stores/tasks.js | 30 +++++------- app/javascript/stores/tickets.js | 26 +++++----- 18 files changed, 147 insertions(+), 123 deletions(-) create mode 100644 app/javascript/commons/custom-axios.js diff --git a/app/javascript/commons/custom-axios.js b/app/javascript/commons/custom-axios.js new file mode 100644 index 0000000..5b6a4b7 --- /dev/null +++ b/app/javascript/commons/custom-axios.js @@ -0,0 +1,49 @@ +import axios from 'axios' + +axios.defaults.headers['X-CSRF-TOKEN'] = $('meta[name=csrf-token]').attr('content') +axios.defaults.headers.common['Accept'] = 'application/json' + +const http = axios; + +export default (Vue, { store }) => { + http.interceptors.request.use((config) => { + store.commit('SET_IS_LOADING', true) + return config; + }, (error) => { + const errorMsg = `${error.response.status} ${error.response.statusText}` + const vm = new Vue() + vm.$bvToast.toast(error.toString(), { + title: errorMsg, + noCloseButton: false, + noAutoHide: true, + variant: 'danger', + }) + + return Promise.reject(error) + }); + + http.interceptors.response.use((response) => { + store.commit('SET_IS_LOADING', true); + return response; + }, (error) => { + const errorMsg = `${error.response.status} ${error.response.statusText}` + const vm = new Vue() + vm.$bvToast.toast(error.toString(), { + title: errorMsg, + noCloseButton: false, + noAutoHide: true, + variant: 'danger', + }) + + return Promise.reject(error) + }); + + Vue.http = http; + Object.defineProperties(Vue.prototype, { + $http: { + get () { + return http; + } + } + }); +}; \ No newline at end of file diff --git a/app/javascript/components/backlogs/StoryModal.vue b/app/javascript/components/backlogs/StoryModal.vue index d0fcd33..735e844 100644 --- a/app/javascript/components/backlogs/StoryModal.vue +++ b/app/javascript/components/backlogs/StoryModal.vue @@ -162,7 +162,6 @@ \ No newline at end of file diff --git a/app/javascript/components/kanban/TaskModal.vue b/app/javascript/components/kanban/TaskModal.vue index 1a9f92a..6f079e8 100644 --- a/app/javascript/components/kanban/TaskModal.vue +++ b/app/javascript/components/kanban/TaskModal.vue @@ -10,7 +10,15 @@ hide-header hide-footer no-fade> -
+
+ +
@@ -166,6 +174,10 @@ import HistoryList from '../commons/HistoryList' import CustomMoment from '../../commons/custom-moment' import urlparse from 'url-parse' import VueClipboard2 from 'vue-clipboard2' +// Import component +import Loading from 'vue-loading-overlay'; +// Import stylesheet +import 'vue-loading-overlay/dist/vue-loading.css'; Vue.use(VueClipboard2) @@ -177,7 +189,8 @@ export default { SelectAssignee, SelectStatus, CommentFormAndList, - HistoryList + HistoryList, + Loading }, name: 'TaskModal', props: { @@ -359,14 +372,33 @@ export default {