diff --git a/api/quality.js b/api/quality.js index 7f2e3f1..a49afe1 100644 --- a/api/quality.js +++ b/api/quality.js @@ -5,14 +5,17 @@ const handler = async (url, event, context) => { const apiKey = process.env.GOOGLE_CLOUD_API_KEY; if (!apiKey) { - throw new Error('API key (GOOGLE_CLOUD_API_KEY) not set'); + throw new Error( + 'Missing Google API. You need to set the `GOOGLE_CLOUD_API_KEY` environment variable' + ); } - const endpoint = `https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=${encodeURIComponent(url)}&category=PERFORMANCE&category=ACCESSIBILITY&category=BEST_PRACTICES&category=SEO&category=PWA&strategy=mobile&key=${apiKey}`; + const endpoint = `https://www.googleapis.com/pagespeedonline/v5/runPagespeed?` + + `url=${encodeURIComponent(url)}&category=PERFORMANCE&category=ACCESSIBILITY` + + `&category=BEST_PRACTICES&category=SEO&category=PWA&strategy=mobile` + + `&key=${apiKey}`; - const response = await axios.get(endpoint); - - return response.data; + return (await axios.get(endpoint)).data; }; module.exports = middleware(handler); diff --git a/api/sitemap.js b/api/sitemap.js index 9d77ec1..8d593e4 100644 --- a/api/sitemap.js +++ b/api/sitemap.js @@ -39,10 +39,8 @@ const handler = async (url) => { return sitemap; } catch (error) { - // If error occurs - console.log(error.message); if (error.code === 'ECONNABORTED') { - return { error: 'Request timed out' }; + return { error: 'Request timed out after 5000ms' }; } else { return { error: error.message }; } diff --git a/src/pages/Results.tsx b/src/pages/Results.tsx index 259d91c..3190287 100644 --- a/src/pages/Results.tsx +++ b/src/pages/Results.tsx @@ -288,7 +288,7 @@ const Results = (): JSX.Element => { addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly }, fetchRequest: () => fetch(`${api}/quality?url=${address}`) .then(res => parseJson(res)) - .then(res => res?.lighthouseResult || { error: 'No Data'}), + .then(res => res?.lighthouseResult || { error: res.error || 'No Data' }), }); // Get the technologies used to build site, using Wappalyzer