UNPKG

laudantiumculpa

Version:
2 lines (1 loc) 1.4 kB
import{V as e,r,h as t,K as s,bk as n,au as a,bl as o,as as d}from"./__bundle-ed5804d1.js";var i=function(i,u){return new Promise((function(p,c){if("undefined"!=typeof XMLHttpRequest){var f=e.of(i),l=f.dispatcher,h=f.logger,q=u.requestId,v=u.method,g=u.url,w=u.headers,m=void 0===w?{}:w,b=u.data,E=void 0===b?"":b,H=u.uploadProgressHandler,S=!1,x=new XMLHttpRequest;for(var y in x.open(v,g),m)x.setRequestHeader(y,m[y]);H&&x.upload.addEventListener("progress",(function(e){e.lengthComputable?H(q,e.loaded,e.total):h.debug("Progress computing failed: `Content-Length` header is not given.")})),x.onabort=function(){c(r.requestCanceled)},x.onerror=function(e){c(r.networkError)},x.onreadystatechange=function(){if(x.readyState===XMLHttpRequest.DONE&&!S)if(0===x.status||x.status>=200&&x.status<400)try{var e=JSON.parse(x.responseText);p(new t(i,e))}catch(u){c(r.networkError)}else try{var d=JSON.parse(x.responseText);if(d){var u=new r(d);if(u.isSessionExpiredError){if(l.dispatch(new s({reason:u.code})),!(x instanceof n)){var f=new a;return l.dispatch(new o({request:x,deferred:f,error:u})),f.promise}}else u.isSessionInvalidatedError&&l.dispatch(new s({reason:u.code}));c(u)}else c(r.requestFailed)}catch(u){c(r.requestFailed)}},l.on((function(e){e instanceof d&&(e.requestId&&e.requestId!==q||(S=!0,x.abort()))})),x.send(E)}else c(r.xmlHttpRequestNotSupported)}))};export{i as xmlHttpRequest};