Skip to content

Instantly share code, notes, and snippets.

@fadziljusri
Last active February 14, 2020 02:41
Show Gist options
  • Save fadziljusri/ba5e3ac518f24471ac549b21a41fa3dc to your computer and use it in GitHub Desktop.
Save fadziljusri/ba5e3ac518f24471ac549b21a41fa3dc to your computer and use it in GitHub Desktop.
axios plugin
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