From 558408b34dfb6cead6ef19cbda322cf70d3ebedf Mon Sep 17 00:00:00 2001 From: Alexander Lebedev Date: Tue, 18 Jul 2023 10:05:32 +0200 Subject: [PATCH] Lower serverity of missing Trustpilot settings ## Describe your changes Reduce noise from Trustpilot not being configured. Warn in production, info otherwise ## Justify why they are needed Improve developer experience ## Checklist before requesting a review - [ ] I have performed a self-review of my code --- .../store/src/services/trustpilot/trustpilot.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/apps/store/src/services/trustpilot/trustpilot.tsx b/apps/store/src/services/trustpilot/trustpilot.tsx index 090d0f90fe..c746da7188 100644 --- a/apps/store/src/services/trustpilot/trustpilot.tsx +++ b/apps/store/src/services/trustpilot/trustpilot.tsx @@ -25,12 +25,16 @@ export const fetchTrustpilotData = async () => { try { const hedvigBusinessUnitId = process.env.TRUSTPILOT_HEDVIG_BUSINESS_UNIT_ID if (!hedvigBusinessUnitId) { - throw new Error('TRUSTPILOT_HEDVIG_BUSINESS_UNIT_ID is not configured') + logMissingSetting( + 'TRUSTPILOT_HEDVIG_BUSINESS_UNIT_ID is not configured, skipping Trustpilot data', + ) + return null } const trustpilotApiKey = process.env.TRUSTPILOT_API_KEY if (!trustpilotApiKey) { - throw new Error('`TRUSTPILOT_API_KEY` is not configured') + logMissingSetting('TRUSTPILOT_API_KEY is not configured, skipping Trustpilot data') + return null } const response = await fetch( @@ -57,3 +61,11 @@ export const fetchTrustpilotData = async () => { return null } } + +const logMissingSetting = (message: string) => { + if (process.env.NODE_ENV === 'production') { + console.warn(message) + } else { + console.log(message) + } +}