@sddxzxqy/browser-support
Version:
ocp browser support lib
2 lines (1 loc) • 1.02 kB
JavaScript
import{__assign as e}from"tslib";import t from"axios";var r=function(){function r(){this.instance=t.create({timeout:1e4,withCredentials:!0})}return r.prototype.onResolve=function(e){var t=e.data,r=e.headers,n=e.status;return Promise.resolve({standardResponse:t,responseHeader:r,httpStatus:n})},r.prototype.onReject=function(e){e.message;var t=e.response,r=t.data,n=t.status,s=t.headers;return r?Promise.reject({standardResponse:r,responseHeader:s,httpStatus:n}):Promise.reject(e)},r.prototype.request=function(t){var r=this,n=t.method;switch(n){case"get":return this.instance.get(t.path,{params:t.data,headers:e({},t.headers)}).then((function(e){return r.onResolve(e)}),(function(e){return r.onReject(e)}));case"post":return this.instance.request({method:t.method,url:t.path,headers:e({},t.headers),data:t.data}).then((function(e){return r.onResolve(e)}),(function(e){return r.onReject(e)}));default:throw new Error("不支持的请求方法".concat(n,"支持的方法get、post"))}},r}();export{r as AxiosHttpClientImpl};