|
|
@ -1,37 +1,36 @@
|
|
|
|
import axios from "axios";
|
|
|
|
import axios from "axios";
|
|
|
|
import { baseURL } from "@/config/request";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const service = axios.create({
|
|
|
|
const service = axios.create({
|
|
|
|
baseURL: baseURL,
|
|
|
|
baseURL: process.env.VUE_APP_NETEASE_API_URL,
|
|
|
|
withCredentials: true,
|
|
|
|
withCredentials: true,
|
|
|
|
timeout: 15000,
|
|
|
|
timeout: 15000
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const errors = new Map([
|
|
|
|
const errors = new Map([
|
|
|
|
[401, 'The token you are using has expired.'],
|
|
|
|
[401, "The token you are using has expired."],
|
|
|
|
[502, null],
|
|
|
|
[502, null],
|
|
|
|
[301, 'You must login to use this feature.'],
|
|
|
|
[301, "You must login to use this feature."],
|
|
|
|
[-1, 'An unexpected error has occurred: '],
|
|
|
|
[-1, "An unexpected error has occurred: "]
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
service.interceptors.response.use(
|
|
|
|
service.interceptors.response.use(
|
|
|
|
(response) => {
|
|
|
|
response => {
|
|
|
|
const res = response.data;
|
|
|
|
const res = response.data;
|
|
|
|
|
|
|
|
|
|
|
|
if (res.code !== 200) {
|
|
|
|
if (res.code !== 200) {
|
|
|
|
alert(
|
|
|
|
alert(
|
|
|
|
errors.has(res.code)
|
|
|
|
errors.has(res.code)
|
|
|
|
? errors.get(res.code)
|
|
|
|
? errors.get(res.code) ||
|
|
|
|
// null = `The server returned ${res.msg}`
|
|
|
|
// null = `The server returned ${res.msg}`
|
|
|
|
|| `The server returned ${res.msg}`
|
|
|
|
`The server returned ${res.msg}`
|
|
|
|
// -1 = default expection message
|
|
|
|
: // -1 = default expection message
|
|
|
|
: errors.get(-1) + res.code
|
|
|
|
errors.get(-1) + res.code
|
|
|
|
);
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return res;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
(error) => {
|
|
|
|
error => {
|
|
|
|
const errMsg = `error: ${error}`;
|
|
|
|
const errMsg = `error: ${error}`;
|
|
|
|
console.log(errMsg);
|
|
|
|
console.log(errMsg);
|
|
|
|
|
|
|
|
|
|
|
|