import{E as t,F as e,G as r}from"./index--q9pcdAZ.js";function n(n){const{requestUrl:s,httpStatus:o,responseContentType:a,responseBodySnippet:i,error:p}=n,u="string"==typeof a&&a.toLowerCase().includes("text/html");t(t=>{t.setTag("api_call",!0),t.setTag("http_status",String(o)),t.setExtras({request_url:s,response_content_type:a,html_fallback_suspeito:u,response_body_snippet:i}),p instanceof Error?e(p):r(`apiFetch falhou: ${s} (${o})`,"error")})}function s(t){return"AbortError"===(null==t?void 0:t.name)||"undefined"!=typeof DOMException&&t instanceof DOMException&&"AbortError"===t.name}async function o(t,e){const r=function(t){try{if("string"==typeof t)return t;if(t instanceof URL)return t.toString();if(t instanceof Request)return t.url}catch{}return String(t)}(t),o="GET"===((null==e?void 0:e.method)??"GET").toUpperCase();let a;try{a=await fetch(t,e)}catch(i){if(s(i))throw i;if(!o)throw n({requestUrl:r,httpStatus:"sem-resposta",responseContentType:null,error:i}),i;await new Promise(t=>setTimeout(t,500));try{a=await fetch(t,e)}catch(p){if(s(p))throw p;throw n({requestUrl:r,httpStatus:"sem-resposta",responseContentType:null,error:p}),p}}if(a.status>=500){const t=a.headers.get("content-type");let e;try{e=(await a.clone().text()).slice(0,500)}catch{e=void 0}n({requestUrl:r,httpStatus:a.status,responseContentType:t,responseBodySnippet:e})}return a}export{o as a};