Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ const urlLinks = 'https://www.zenrows.com/';
const urlPremium = 'https://www.google.com/search?q=Ariana+Grande';
const testPost = 'https://httpbin.org/anything';

function handleError(error) {
console.error(error.message);
if (error.response) {
console.error(error.response.data);
}
}

(async () => {
const client = new ZenRows(apiKey, { concurrency: 5, retries: 1 });

Expand All @@ -27,10 +34,7 @@ const testPost = 'https://httpbin.org/anything';
]
*/
} catch (error) {
console.error(error.message);
if (error.response) {
console.error(error.response.data);
}
handleError(error)
}

try {
Expand All @@ -55,10 +59,7 @@ const testPost = 'https://httpbin.org/anything';
}
*/
} catch (error) {
console.error(error.message);
if (error.response) {
console.error(error.response.data);
}
handleError(error)
}

try {
Expand All @@ -78,10 +79,7 @@ const testPost = 'https://httpbin.org/anything';
console.log(rejected);
console.log(fulfilled);
} catch (error) {
console.error(error.message);
if (error.response) {
console.error(error.response.data);
}
handleError(error)
}

try {
Expand All @@ -99,9 +97,6 @@ const testPost = 'https://httpbin.org/anything';
...
*/
} catch (error) {
console.error(error.message);
if (error.response) {
console.error(error.response.data);
}
handleError(error)
}
})();
27 changes: 11 additions & 16 deletions examples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ const urlLinks = 'https://www.zenrows.com/';
const urlPremium = 'https://www.google.com/search?q=Ariana+Grande';
const testPost = 'https://httpbin.org/anything';

function handleError(error: unknown) {
console.error((error as Error).message);
if (axios.isAxiosError(error)) {
console.error(error.response?.data);
}
}

(async () => {
const client = new ZenRows(apiKey, { concurrency: 5, retries: 1 });

Expand All @@ -22,10 +29,7 @@ const testPost = 'https://httpbin.org/anything';

console.log(data);
} catch (error: unknown) {
console.error((error as Error).message);
if (axios.isAxiosError(error)) {
console.error(error.response?.data);
}
handleError(error);
}

try {
Expand All @@ -50,10 +54,7 @@ const testPost = 'https://httpbin.org/anything';
}
*/
} catch (error: unknown) {
console.error((error as Error).message);
if (axios.isAxiosError(error)) {
console.error(error.response?.data);
}
handleError(error);
}

try {
Expand All @@ -73,10 +74,7 @@ const testPost = 'https://httpbin.org/anything';
console.log(rejected);
console.log(fulfilled);
} catch (error: unknown) {
console.error((error as Error).message);
if (axios.isAxiosError(error)) {
console.error(error.response?.data);
}
handleError(error);
}

try {
Expand All @@ -94,9 +92,6 @@ const testPost = 'https://httpbin.org/anything';
...
*/
} catch (error: unknown) {
console.error((error as Error).message);
if (axios.isAxiosError(error)) {
console.error(error.response?.data);
}
handleError(error);
}
})();
8 changes: 1 addition & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,7 @@ class ZenRows {
axiosRetry(axios, {
retries,
retryDelay: axiosRetry.exponentialDelay,
retryCondition: (error) => {
if (error.response?.status === 429) {
return true;
}

return axiosRetry.isNetworkOrIdempotentRequestError(error);
},
retryCondition: (error) => error.response?.status === 429 || axiosRetry.isNetworkOrIdempotentRequestError(error),
});
}
}
Expand Down