Return plain JSON, to be handled by middleware instead

This commit is contained in:
Alicia Sykes
2023-09-03 16:58:46 +01:00
parent c169a3762d
commit 8a7b024e99
6 changed files with 13 additions and 51 deletions

View File

@ -25,10 +25,7 @@ const handler = async (url) => {
}
if (!sitemapUrl) {
return {
statusCode: 404,
body: JSON.stringify({ skipped: 'No sitemap found' }),
};
return { skipped: 'No sitemap found' };
}
sitemapRes = await axios.get(sitemapUrl, { timeout: 5000 });
@ -40,23 +37,14 @@ const handler = async (url) => {
const parser = new xml2js.Parser();
const sitemap = await parser.parseStringPromise(sitemapRes.data);
return {
statusCode: 200,
body: JSON.stringify(sitemap),
};
return sitemap;
} catch (error) {
// If error occurs
console.log(error.message);
if (error.code === 'ECONNABORTED') {
return {
statusCode: 500,
body: JSON.stringify({ error: 'Request timed out' }),
};
return { error: 'Request timed out' };
} else {
return {
statusCode: 500,
body: JSON.stringify({ error: error.message }),
};
return { error: error.message };
}
}
};