Created
January 26, 2019 05:59
-
-
Save milk1000cc/063032c71521061458a2adf714cec616 to your computer and use it in GitHub Desktop.
axios + rails csrf token + common error handling
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
import axios from 'axios' | |
import { csrfToken } from 'rails-ujs' | |
const myAxios = axios.create() | |
myAxios.defaults.headers.common['X-CSRF-Token'] = csrfToken() | |
myAxios.interceptors.response.use(res => res, error => { | |
const msg = "エラーが発生しました。\n\nしばらく時間をおいてから、もう一度お試しください。\n" + | |
"ご不便をおかけしてしまい、大変申し訳ございません。" | |
alert(msg) | |
return Promise.reject(error) | |
}) | |
export default myAxios |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment