feat(sdk): enforce timeout on client-side if set (#1204)

This commit is contained in:
Gergő Móricz 2025-02-20 13:35:31 +01:00 committed by GitHub
parent dc1501527a
commit c75522f535
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 3 deletions

View File

@ -535,7 +535,7 @@ export default class FirecrawlApp {
const response: AxiosResponse = await axios.post( const response: AxiosResponse = await axios.post(
this.apiUrl + `/v1/scrape`, this.apiUrl + `/v1/scrape`,
jsonData, jsonData,
{ headers } { headers, timeout: params?.timeout !== undefined ? (params.timeout + 5000) : undefined },
); );
if (response.status === 200) { if (response.status === 200) {
const responseData = response.data; const responseData = response.data;
@ -1262,7 +1262,7 @@ export default class FirecrawlApp {
data: any, data: any,
headers: AxiosRequestHeaders headers: AxiosRequestHeaders
): Promise<AxiosResponse> { ): Promise<AxiosResponse> {
return axios.post(url, data, { headers }); return axios.post(url, data, { headers, timeout: (data?.timeout ? (data.timeout + 5000) : undefined) });
} }
/** /**

View File

@ -145,6 +145,7 @@ class FirecrawlApp:
f'{self.api_url}{endpoint}', f'{self.api_url}{endpoint}',
headers=headers, headers=headers,
json=scrape_params, json=scrape_params,
timeout=(scrape_params["timeout"] + 5000 if "timeout" in scrape_params else None),
) )
if response.status_code == 200: if response.status_code == 200:
try: try:
@ -925,7 +926,7 @@ class FirecrawlApp:
requests.RequestException: If the request fails after the specified retries. requests.RequestException: If the request fails after the specified retries.
""" """
for attempt in range(retries): for attempt in range(retries):
response = requests.post(url, headers=headers, json=data) response = requests.post(url, headers=headers, json=data, timeout=((data["timeout"] + 5000) if "timeout" in data else None))
if response.status_code == 502: if response.status_code == 502:
time.sleep(backoff_factor * (2 ** attempt)) time.sleep(backoff_factor * (2 ** attempt))
else: else: