mirror of
https://git.mirrors.martin98.com/https://github.com/mendableai/firecrawl
synced 2025-08-12 16:28:59 +08:00
feat(sdk): enforce timeout on client-side if set (#1204)
This commit is contained in:
parent
dc1501527a
commit
c75522f535
@ -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) });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user