@atlas-kitchen/adyen-web
Version:
3 lines (2 loc) • 1.38 kB
JavaScript
import{DEFAULT_HTTP_TIMEOUT as e,FALLBACK_CONTEXT as r}from"../config.js";import o from"../Errors/AdyenCheckoutError.js";function t(t,n){const{headers:s=[],errorLevel:c="warn",errorCode:i,loadingContext:l=r,method:d="GET",path:u,timeout:f=e}=t,m={method:d,mode:"cors",cache:"default",credentials:"same-origin",headers:{Accept:"application/json, text/plain, */*","Content-Type":"POST"===d?"application/json":"text/plain",...s},redirect:"follow",referrerPolicy:"no-referrer-when-downgrade",...AbortSignal?.timeout&&{signal:AbortSignal?.timeout(f)},...n&&{body:JSON.stringify(n)}},g=`${l}${u}`;return fetch(g,m).then((async e=>{const r=await e.json();if(e.ok)return r;if(function(e){return e&&e.errorCode&&e.errorType&&e.message&&e.status}(r))return void a({message:r.message,level:c,cause:r,code:i});a({message:t.errorMessage||`Service at ${g} is not available`,level:c,cause:r,code:i})})).catch((e=>{if(e instanceof o)throw e;a({message:t.errorMessage||`Call to ${g} failed. Error= ${e}`,level:c,cause:e,code:i})}))}function a({message:e,level:r,cause:t,code:a}){switch(r){case"silent":break;case"info":case"warn":case"error":console[r](e);break;default:throw new o("NETWORK_ERROR",e,{cause:t,code:a})}}function n(e,r){return t({...e,method:"GET"},r)}function s(e,r){return t({...e,method:"POST"},r)}export{t as http,n as httpGet,s as httpPost};
//# sourceMappingURL=http.js.map