78 lines
2.1 KiB
JavaScript
78 lines
2.1 KiB
JavaScript
var __defProp = Object.defineProperty;
|
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
var __export = (target, all) => {
|
|
for (var name in all)
|
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
};
|
|
var __copyProps = (to, from, except, desc) => {
|
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
for (let key of __getOwnPropNames(from))
|
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
}
|
|
return to;
|
|
};
|
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
|
|
// src/index.tsx
|
|
var src_exports = {};
|
|
__export(src_exports, {
|
|
request: () => request
|
|
});
|
|
module.exports = __toCommonJS(src_exports);
|
|
var request = {
|
|
timeout: 1e3,
|
|
// other axios options you want
|
|
errorConfig: {
|
|
// @ts-ignore
|
|
errorHandler(error, opts) {
|
|
},
|
|
// @ts-ignore
|
|
errorThrower(res) {
|
|
console.log("res", res);
|
|
}
|
|
},
|
|
// 请求
|
|
requestInterceptors: [
|
|
// 一个二元组,第一个元素是 request 拦截器,第二个元素是错误处理
|
|
[
|
|
(url, options) => {
|
|
return {
|
|
url,
|
|
options: {
|
|
...options,
|
|
headers: {
|
|
authorization: "test"
|
|
// ...(refererSuffix ? { zhst_referer: `${baseUrl}${refererSuffix}` } : {}),
|
|
}
|
|
}
|
|
};
|
|
},
|
|
(error) => {
|
|
return Promise.reject(error);
|
|
}
|
|
]
|
|
],
|
|
// 返回
|
|
responseInterceptors: [
|
|
// 一个二元组,第一个元素是 request 拦截器,第二个元素是错误处理
|
|
[
|
|
(response) => {
|
|
if (response.status !== 200) {
|
|
throw Error(JSON.stringify(response.data));
|
|
}
|
|
return response;
|
|
},
|
|
(error) => {
|
|
return Promise.reject(error);
|
|
}
|
|
]
|
|
]
|
|
};
|
|
// Annotate the CommonJS export names for ESM import in node:
|
|
0 && (module.exports = {
|
|
request
|
|
});
|