Last active
February 14, 2020 02:41
-
-
Save fadziljusri/ba5e3ac518f24471ac549b21a41fa3dc to your computer and use it in GitHub Desktop.
axios plugin
This file contains hidden or 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'; | |
export const axios = _axios.create({ | |
headers: { | |
'Content-Type': 'application/json;charset=UTF-8', | |
} | |
}); | |
export const handleResponse = function (response) { | |
const data = response.data; | |
return data; | |
} | |
export const handleErr = function (err) { | |
const error = err.response || {}; | |
// console.log(err); | |
// // :TODO | |
// if (error.status === 401) { | |
// console.log("Unauthorized! do logout"); | |
// store.dispatch('accounts/logout'); | |
// } | |
if (!error.status) { | |
return Promise.reject({ | |
status: "failed", | |
message: "Internal Server Error" | |
}); | |
} | |
else if (!error.data) { | |
return Promise.reject({ | |
status: "failed", | |
message: "Error data does not exist" | |
}); | |
} else { | |
return Promise.reject(error.data); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment