UNPKG

@fast-china/axios

Version:

Fast Axios 请求工具库.

3 lines (2 loc) 2.79 kB
import{AxiosError as e}from"axios";import{isNil as t}from"lodash-unified";import"./types/index.mjs";import{LoadingManage as r}from"./types/loading.mjs";import{MessageManage as s}from"./types/message.mjs";import{MessageBoxManage as i}from"./types/messageBox.mjs";import{CacheManage as o}from"./types/cache.mjs";import{CryptoManage as n}from"./types/crypto.mjs";import{InterceptorsManage as h}from"./types/interceptors.mjs";class a{static instance;constructor(t){this.setOptions(t),this.errorCode={default:"请求失败,请稍后再试!",cancelDuplicate:"重复请求,自动取消!",offLine:"您断网了!",fileDownloadError:"文件下载失败或此文件不存在!",302:"接口重定向了!",400:"参数不正确!",401:"您没有权限操作(令牌、用户名、密码错误)!",403:"您的访问是被禁止的!",404:"请求的资源不存在!",405:"请求的格式不正确!",408:"请求超时!",409:"系统已存在相同数据!",410:"请求的资源被永久删除,且不会再得到的!",422:"当创建一个对象时,发生一个验证错误!",429:"请求过于频繁,请稍后再试!",500:"服务器内部错误!",501:"服务未实现!",502:"网关错误!",503:"服务不可用,服务器暂时过载或维护!",504:"服务暂时无法访问,请稍后再试!",505:"HTTP版本不受支持!",[e.ETIMEDOUT]:"请求超时!",[e.ERR_CANCELED]:"连接已被取消!",[e.ECONNABORTED]:"连接中断,服务器暂时过载或维护!",[e.ERR_NETWORK]:"网关错误,服务不可用,服务器暂时过载或维护!","request:fail":"网关错误,服务不可用,服务器暂时过载或维护!"},this.loading=new r,this.message=new s,this.messageBox=new i,this.cache=new o,this.crypto=new n,this.interceptors=new h}setOptions(e){return e?.baseUrl&&(this._baseUrl=e.baseUrl),this._timeout=e?.timeout?e.timeout:this._timeout??6e4,e?.headers&&(this._headers={...this._headers??{},...e.headers}),t(e?.requestCipher)?this._requestCipher=!!t(this._requestCipher)||this._requestCipher:this._requestCipher=e.requestCipher,this}_baseUrl;get baseUrl(){return this._baseUrl}_timeout;get timeout(){return this._timeout}_headers;get headers(){return this._headers}_requestCipher;get requestCipher(){return this._requestCipher}errorCode;loading;message;messageBox;cache;crypto;interceptors;addErrorCode(e,t){if("string"==typeof e||"number"==typeof e)this.errorCode[e]=t;else for(const r in e)this.errorCode[r]=e[r];return this}}const m=(e,t=!1)=>{if(t)return new a(e);if(!a.instance){const t=new a(e);a.instance=t}return a.instance},p=()=>{if(!a.instance)throw new Error("请先调用 'createFastAxios' 初始化 'fast-axios'。");return a.instance};export{m as createFastAxios,p as useFastAxios}; //# sourceMappingURL=fastAxios.mjs.map