fix: structure logged data
This commit is contained in:
@@ -32,7 +32,12 @@ export const hotelQueryRouter = router({
|
||||
params.include = include.join(",")
|
||||
}
|
||||
|
||||
console.info("api.hotels.hotel start")
|
||||
console.info(
|
||||
"api.hotels.hotel start",
|
||||
JSON.stringify({
|
||||
query: { hotelId, params: params.toString() },
|
||||
})
|
||||
)
|
||||
const apiResponse = await api.get(
|
||||
`${api.endpoints.v1.hotels}/${hotelId}`,
|
||||
{
|
||||
@@ -45,7 +50,13 @@ export const hotelQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!apiResponse.ok) {
|
||||
console.error("api.hotels.hotel error, ", JSON.stringify(apiResponse))
|
||||
console.error(
|
||||
"api.hotels.hotel error",
|
||||
JSON.stringify({
|
||||
query: { hotelId, params: params.toString() },
|
||||
error: apiResponse,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
const apiJson = await apiResponse.json()
|
||||
@@ -53,8 +64,11 @@ export const hotelQueryRouter = router({
|
||||
|
||||
if (!validatedHotelData.success) {
|
||||
console.error(
|
||||
"api.hotels.hotel validation error ",
|
||||
JSON.stringify(validatedHotelData.error)
|
||||
"api.hotels.hotel validation error",
|
||||
JSON.stringify({
|
||||
query: { hotelId, params: params.toString() },
|
||||
error: validatedHotelData.error,
|
||||
})
|
||||
)
|
||||
throw badRequestError()
|
||||
}
|
||||
@@ -63,18 +77,28 @@ export const hotelQueryRouter = router({
|
||||
|
||||
const roomCategories = included
|
||||
? included
|
||||
.filter((item) => item.type === "roomcategories")
|
||||
.map((roomCategory) => {
|
||||
const validatedRoom = roomSchema.safeParse(roomCategory)
|
||||
if (!validatedRoom.success) {
|
||||
console.error(`Get Room Category Data - Verified Data Error`)
|
||||
console.error(validatedRoom.error)
|
||||
throw badRequestError()
|
||||
}
|
||||
return validatedRoom.data
|
||||
})
|
||||
.filter((item) => item.type === "roomcategories")
|
||||
.map((roomCategory) => {
|
||||
const validatedRoom = roomSchema.safeParse(roomCategory)
|
||||
if (!validatedRoom.success) {
|
||||
console.error(
|
||||
"api.hotels.hotel validation error",
|
||||
JSON.stringify({
|
||||
query: { hotelId, params: params.toString() },
|
||||
error: validatedRoom.error,
|
||||
})
|
||||
)
|
||||
throw badRequestError()
|
||||
}
|
||||
return validatedRoom.data
|
||||
})
|
||||
: []
|
||||
console.info("api.hotels.hotel success")
|
||||
console.info(
|
||||
"api.hotels.hotel success",
|
||||
JSON.stringify({
|
||||
query: { hotelId, params: params.toString() },
|
||||
})
|
||||
)
|
||||
return {
|
||||
hotel: validatedHotelData.data.data.attributes,
|
||||
roomCategories: roomCategories,
|
||||
@@ -90,31 +114,36 @@ export const hotelQueryRouter = router({
|
||||
// const apiLang = toApiLang(language)
|
||||
// params.set("hotelId", hotelId.toString())
|
||||
// params.set("language", apiLang)
|
||||
console.info("api.hotels.rates start")
|
||||
console.info("api.hotels.rates start", JSON.stringify({}))
|
||||
const validatedHotelData = getRatesSchema.safeParse(tempRatesData)
|
||||
|
||||
if (!tempRatesData) {
|
||||
console.error("api.hotels.rates error, ", {})
|
||||
console.error("api.hotels.rates error", JSON.stringify({ error: null }))
|
||||
//Can't return null here since consuming component does not handle null yet
|
||||
// return null
|
||||
}
|
||||
if (!validatedHotelData.success) {
|
||||
console.error(
|
||||
"api.hotels.rates validation error ",
|
||||
JSON.stringify(validatedHotelData.error)
|
||||
"api.hotels.rates validation error",
|
||||
JSON.stringify({
|
||||
error: validatedHotelData.error,
|
||||
})
|
||||
)
|
||||
throw badRequestError()
|
||||
}
|
||||
console.info("api.hotels.rates success")
|
||||
console.info("api.hotels.rates success", JSON.stringify({}))
|
||||
return validatedHotelData.data
|
||||
}),
|
||||
getFilters: publicProcedure
|
||||
.input(getFiltersInputSchema)
|
||||
.query(async ({ input, ctx }) => {
|
||||
console.info("api.hotels.filters start")
|
||||
console.info("api.hotels.filters start", JSON.stringify({}))
|
||||
|
||||
if (!tempFilterData) {
|
||||
console.error("api.hotels.filters error, ", {})
|
||||
console.error(
|
||||
"api.hotels.filters error",
|
||||
JSON.stringify({ error: null })
|
||||
)
|
||||
//Can't return null here since consuming component does not handle null yet
|
||||
// return null
|
||||
}
|
||||
@@ -123,11 +152,13 @@ export const hotelQueryRouter = router({
|
||||
if (!validateFilterData.success) {
|
||||
console.error(
|
||||
"api.hotels.filters validation error",
|
||||
JSON.stringify(validateFilterData.error)
|
||||
JSON.stringify({
|
||||
error: validateFilterData.error,
|
||||
})
|
||||
)
|
||||
throw badRequestError()
|
||||
}
|
||||
|
||||
console.info("api.hotels.rates success", JSON.stringify({}))
|
||||
return validateFilterData.data
|
||||
}),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user