import{w as t,p as e,q as r}from"./index-Hzc6Jvc7.js";function n(n){const{requestUrl:s,httpStatus:o,responseContentType:a,responseBodySnippet:i,error:p}=n,c="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:c,response_body_snippet:i}),p instanceof Error?e(p):r(`apiFetch falhou: ${s} (${o})`,"error")})}async function s(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);let s;try{s=await fetch(t,e)}catch(o){if("AbortError"===(null==o?void 0:o.name)||"undefined"!=typeof DOMException&&o instanceof DOMException&&"AbortError"===o.name)throw o;throw n({requestUrl:r,httpStatus:"sem-resposta",responseContentType:null,error:o}),o}if(s.status>=500){const t=s.headers.get("content-type");let e;try{e=(await s.clone().text()).slice(0,500)}catch{e=void 0}n({requestUrl:r,httpStatus:s.status,responseContentType:t,responseBodySnippet:e})}return s}export{s as a};