Skip to content

Commit

Permalink
Lower serverity of missing Trustpilot settings
Browse files Browse the repository at this point in the history
  • Loading branch information
alebedev committed Jul 17, 2023
1 parent ae844d7 commit c64fe2e
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions apps/store/src/services/trustpilot/trustpilot.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as process from 'process'
import { atom, useAtomValue } from 'jotai'
import { useHydrateAtoms } from 'jotai/utils'
import { type TrustpilotData } from './trustpilot.types'
Expand Down Expand Up @@ -25,12 +26,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(
Expand All @@ -57,3 +62,11 @@ export const fetchTrustpilotData = async () => {
return null
}
}

const logMissingSetting = (message: string) => {
if (process.env.NODE_ENV === 'production') {
console.warn(message)
} else {
console.log(message)
}
}

0 comments on commit c64fe2e

Please sign in to comment.