From 537a6acf6ee5574b84ef7c4929c53c2f8c889ae2 Mon Sep 17 00:00:00 2001 From: paraschi Date: Tue, 20 Aug 2024 22:37:44 +0300 Subject: [PATCH] fix: unexpected close tag issue --- src/sitemap/handler.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/sitemap/handler.js b/src/sitemap/handler.js index f63d2714..7eac7f02 100644 --- a/src/sitemap/handler.js +++ b/src/sitemap/handler.js @@ -138,11 +138,18 @@ export function isSitemapContentValid(sitemapContent) { export async function checkSitemap(sitemapUrl, log) { try { const sitemapContent = await fetchContent(sitemapUrl, log); - const isValidFormat = isSitemapContentValid(sitemapContent); - const isSitemapIndex = isValidFormat && sitemapContent.payload.includes(''); - const isText = isValidFormat && sitemapContent.type === 'text/plain'; + if (!sitemapContent || !sitemapContent.payload) { + log.error(`No content received from ${sitemapUrl}`); + return { + existsAndIsValid: false, + reasons: [ERROR_CODES.SITEMAP_NOT_FOUND], + details: { sitemapContent: {}, isText: false, isSitemapIndex: false }, + }; + } + const isValidFormat = isSitemapContentValid(sitemapContent); if (!isValidFormat) { + log.error(`Invalid sitemap format at ${sitemapUrl}`); return { existsAndIsValid: false, reasons: [ERROR_CODES.SITEMAP_FORMAT], @@ -150,6 +157,9 @@ export async function checkSitemap(sitemapUrl, log) { }; } + const isSitemapIndex = sitemapContent.payload.includes(''); + const isText = sitemapContent.type === 'text/plain'; + log.info(`Processed ${sitemapUrl}: isSitemapIndex=${isSitemapIndex}`); return { existsAndIsValid: true, @@ -157,13 +167,7 @@ export async function checkSitemap(sitemapUrl, log) { details: { sitemapContent, isText, isSitemapIndex }, }; } catch (error) { - if (error.message.includes('404')) { - return { - existsAndIsValid: false, - reasons: [ERROR_CODES.SITEMAP_NOT_FOUND], - details: { sitemapContent: {}, isText: false, isSitemapIndex: false }, - }; - } + log.error(`Error processing sitemap at ${sitemapUrl}: ${error.message}`); return { existsAndIsValid: false, reasons: [ERROR_CODES.FETCH_ERROR],