mirror of
https://github.com/Lissy93/web-check.git
synced 2025-05-14 19:24:30 +02:00
Update timeout message for sitemap
This commit is contained in:
parent
7a8e694abc
commit
ada1dccc5b
@ -6,15 +6,17 @@ const xml2js = require('xml2js');
|
|||||||
const handler = async (url) => {
|
const handler = async (url) => {
|
||||||
let sitemapUrl = `${url}/sitemap.xml`;
|
let sitemapUrl = `${url}/sitemap.xml`;
|
||||||
|
|
||||||
|
const hardTimeOut = 5000;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Try to fetch sitemap directly
|
// Try to fetch sitemap directly
|
||||||
let sitemapRes;
|
let sitemapRes;
|
||||||
try {
|
try {
|
||||||
sitemapRes = await axios.get(sitemapUrl, { timeout: 5000 });
|
sitemapRes = await axios.get(sitemapUrl, { timeout: hardTimeOut });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.response && error.response.status === 404) {
|
if (error.response && error.response.status === 404) {
|
||||||
// If sitemap not found, try to fetch it from robots.txt
|
// If sitemap not found, try to fetch it from robots.txt
|
||||||
const robotsRes = await axios.get(`${url}/robots.txt`, { timeout: 5000 });
|
const robotsRes = await axios.get(`${url}/robots.txt`, { timeout: hardTimeOut });
|
||||||
const robotsTxt = robotsRes.data.split('\n');
|
const robotsTxt = robotsRes.data.split('\n');
|
||||||
|
|
||||||
for (let line of robotsTxt) {
|
for (let line of robotsTxt) {
|
||||||
@ -28,7 +30,7 @@ const handler = async (url) => {
|
|||||||
return { skipped: 'No sitemap found' };
|
return { skipped: 'No sitemap found' };
|
||||||
}
|
}
|
||||||
|
|
||||||
sitemapRes = await axios.get(sitemapUrl, { timeout: 5000 });
|
sitemapRes = await axios.get(sitemapUrl, { timeout: hardTimeOut });
|
||||||
} else {
|
} else {
|
||||||
throw error; // If other error, throw it
|
throw error; // If other error, throw it
|
||||||
}
|
}
|
||||||
@ -40,7 +42,7 @@ const handler = async (url) => {
|
|||||||
return sitemap;
|
return sitemap;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.code === 'ECONNABORTED') {
|
if (error.code === 'ECONNABORTED') {
|
||||||
return { error: 'Request timed out after 5000ms' };
|
return { error: `Request timed-out after ${hardTimeOut}ms` };
|
||||||
} else {
|
} else {
|
||||||
return { error: error.message };
|
return { error: error.message };
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user