summaryrefslogtreecommitdiffstats
path: root/src/main.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.js')
-rw-r--r--src/main.js20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/main.js b/src/main.js
index 571646471..9a70d470f 100644
--- a/src/main.js
+++ b/src/main.js
@@ -1,10 +1,11 @@
import Vue from 'vue'
import VueRouter from 'vue-router'
import Vuex, { Store } from 'vuex'
+import axios from '@nextcloud/axios'
import App from './App.vue'
import router from './routes'
-import mainStore from './store'
+import mainStore, { MUTATIONS } from './store'
import { Tooltip } from '@nextcloud/vue'
@@ -20,6 +21,23 @@ Vue.directive('tooltip', Tooltip)
const store = new Store(mainStore)
+/**
+ * Handles errors returned during application runtime
+ *
+ * @param {Error} error Error thrown
+ * @return Promise<Error>
+ */
+const handleErrors = function(error) {
+ store.commit(MUTATIONS.SET_ERROR, error)
+ return Promise.reject(error)
+}
+
+axios.interceptors.response.use(undefined /* onSuccessCallback is intentionally undefined (triggers on 2xx responses) */,
+ // Any status codes that falls outside the range of 2xx cause this function to trigger
+ handleErrors,
+)
+
+Vue.config.errorHandler = handleErrors
export default new Vue({
router,
store,