You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1008 B
44 lines
1008 B
import axios from "axios"; |
|
|
|
//跨域请求,允许保存cookie |
|
axios.defaults.withCredentials = true; |
|
|
|
//返回其他状态码 |
|
axios.defaults.validateStatus = function (status) { |
|
return status >= 200 && status <= 500; |
|
}; |
|
//跨域请求,允许保存cookie |
|
axios.defaults.withCredentials = true; |
|
|
|
//HTTP Request拦截 |
|
axios.interceptors.request.use( |
|
(config) => { |
|
config.headers["Content-Type"] = "application/json"; |
|
return config; |
|
}, |
|
(error) => { |
|
console.error("Request interceptors:", error); |
|
return Promise.reject(error); |
|
} |
|
); |
|
|
|
//HTTP Response拦截 |
|
axios.interceptors.response.use( |
|
(res) => { |
|
const ok = res.data.Success || false, |
|
status = res.status || 200, |
|
message = res.data.AllMessages || "Internal Server Error!"; |
|
|
|
if (!ok && !status) { |
|
return Promise.reject(new Error(message)); |
|
} |
|
|
|
return res.data; |
|
}, |
|
(error) => { |
|
console.error("Response interceptors:", error); |
|
return Promise.reject(error); |
|
} |
|
); |
|
|
|
export default axios;
|
|
|