36 lines
955 B
JavaScript
36 lines
955 B
JavaScript
"use strict";
|
|
const common_vendor = require("../common/vendor.js");
|
|
const config_setting = require("../config/setting.js");
|
|
const http = new common_vendor.Request();
|
|
http.setConfig((config) => {
|
|
config.baseURL = config_setting.API_BASE_URL;
|
|
return config;
|
|
});
|
|
http.interceptors.request.use((config) => {
|
|
const token = common_vendor.index.getStorageSync("access_token");
|
|
config.header = {
|
|
...config.header,
|
|
TenantId: config_setting.TENANT_ID
|
|
};
|
|
if (token) {
|
|
config.header.Authorization = token;
|
|
}
|
|
if (config.data) {
|
|
config.data.tenantId = config_setting.TENANT_ID;
|
|
}
|
|
return config;
|
|
}, (config) => {
|
|
return Promise.reject(config);
|
|
});
|
|
http.interceptors.response.use((response) => {
|
|
if (response.data.code == 401) ;
|
|
if (response.data.code == 1) {
|
|
return Promise.reject(response.data);
|
|
}
|
|
return response;
|
|
}, (response) => {
|
|
console.log(response);
|
|
return Promise.reject(response);
|
|
});
|
|
exports.http = http;
|