Merged in feature/wrap-logging (pull request #2511)
Feature/wrap logging * feat: change all logging to go through our own logger function so that we can control log levels * move packages/trpc to using our own logger * merge Approved-by: Linus Flood
This commit is contained in:
@@ -4,6 +4,7 @@ import stringify from "json-stable-stringify-without-jsonify"
|
||||
import { Lang } from "@scandic-hotels/common/constants/language"
|
||||
import { selectRate } from "@scandic-hotels/common/constants/routes/hotelReservation"
|
||||
import { getCacheClient } from "@scandic-hotels/common/dataCache"
|
||||
import { createLogger } from "@scandic-hotels/common/logger/createLogger"
|
||||
import { createCounter } from "@scandic-hotels/common/telemetry"
|
||||
import { chunk } from "@scandic-hotels/common/utils/chunk"
|
||||
|
||||
@@ -64,6 +65,8 @@ import type {
|
||||
import type { Cities } from "./output"
|
||||
export const locationsAffix = "locations"
|
||||
|
||||
const hotelUtilsLogger = createLogger("hotelUtils")
|
||||
|
||||
export async function getCitiesByCountry({
|
||||
countries,
|
||||
lang,
|
||||
@@ -101,8 +104,11 @@ export async function getCitiesByCountry({
|
||||
const countryJson = await countryResponse.json()
|
||||
const citiesByCountry = citiesByCountrySchema.safeParse(countryJson)
|
||||
if (!citiesByCountry.success) {
|
||||
console.error(`Unable to parse cities by country ${country}`)
|
||||
console.error(citiesByCountry.error)
|
||||
hotelUtilsLogger.error(
|
||||
`Unable to parse cities by country ${country}`,
|
||||
citiesByCountry.error
|
||||
)
|
||||
|
||||
throw new Error(`Unable to parse cities by country ${country}`)
|
||||
}
|
||||
return { ...citiesByCountry.data, country }
|
||||
@@ -160,8 +166,10 @@ export async function getCountries({
|
||||
const countriesJson = await countryResponse.json()
|
||||
const countries = countriesSchema.safeParse(countriesJson)
|
||||
if (!countries.success) {
|
||||
console.info(`Validation for countries failed`)
|
||||
console.error(countries.error)
|
||||
hotelUtilsLogger.error(
|
||||
`Validation for countries failed`,
|
||||
countries.error
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -447,8 +455,10 @@ export async function getLocations({
|
||||
const apiJson = await apiResponse.json()
|
||||
const verifiedLocations = locationsSchema.safeParse(apiJson)
|
||||
if (!verifiedLocations.success) {
|
||||
console.info(`Locations Verification Failed`)
|
||||
console.error(verifiedLocations.error)
|
||||
hotelUtilsLogger.error(
|
||||
`Locations Verification Failed`,
|
||||
verifiedLocations.error
|
||||
)
|
||||
throw new Error("Unable to parse locations")
|
||||
}
|
||||
const chunkedLocations = chunk(verifiedLocations.data.data, 10)
|
||||
@@ -471,10 +481,10 @@ export async function getLocations({
|
||||
country,
|
||||
}
|
||||
} else {
|
||||
console.info(
|
||||
`Location cannot be found in any of the countries cities`
|
||||
hotelUtilsLogger.error(
|
||||
`Location cannot be found in any of the countries cities`,
|
||||
location
|
||||
)
|
||||
console.info(location)
|
||||
}
|
||||
}
|
||||
} else if (location.type === "hotels") {
|
||||
@@ -614,9 +624,10 @@ export async function getCity({
|
||||
const cityJson = await cityResponse.json()
|
||||
const city = citiesSchema.safeParse(cityJson)
|
||||
if (!city.success) {
|
||||
console.info(`Validation of city failed`)
|
||||
console.info(`cityUrl: ${cityUrl}`)
|
||||
console.error(city.error)
|
||||
hotelUtilsLogger.error(`Validation of city failed`, {
|
||||
error: city.error,
|
||||
cityUrl,
|
||||
})
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user