-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from kaishuu0123/feat/error-handling
Implement error handling for frontend.
- Loading branch information
Showing
23 changed files
with
280 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', false); | ||
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; | ||
} | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.