fix: structure logged data
This commit is contained in:
@@ -42,7 +42,7 @@ async function getVerifiedUser({ session }: { session: Session }) {
|
||||
if (session.token.expires_at && session.token.expires_at < now) {
|
||||
return { error: true, cause: "token_expired" } as const
|
||||
}
|
||||
console.info("api.user.profile start,")
|
||||
console.info("api.user.profile start", JSON.stringify({}))
|
||||
const apiResponse = await api.get(api.endpoints.v1.profile, {
|
||||
cache: "no-store",
|
||||
headers: {
|
||||
@@ -51,7 +51,12 @@ async function getVerifiedUser({ session }: { session: Session }) {
|
||||
})
|
||||
|
||||
if (!apiResponse.ok) {
|
||||
console.error("api.user.profile error ", JSON.stringify(apiResponse))
|
||||
console.error(
|
||||
"api.user.profile error",
|
||||
JSON.stringify({
|
||||
error: apiResponse,
|
||||
})
|
||||
)
|
||||
if (apiResponse.status === 401) {
|
||||
return { error: true, cause: "unauthorized" } as const
|
||||
} else if (apiResponse.status === 403) {
|
||||
@@ -68,16 +73,16 @@ async function getVerifiedUser({ session }: { session: Session }) {
|
||||
|
||||
const apiJson = await apiResponse.json()
|
||||
if (!apiJson.data?.attributes) {
|
||||
console.error("api.user.profile data error")
|
||||
console.error("api.user.profile data error", JSON.stringify({})) // not passing the data to avoid logging sensitive data
|
||||
return null
|
||||
}
|
||||
|
||||
const verifiedData = getUserSchema.safeParse(apiJson.data.attributes)
|
||||
if (!verifiedData.success) {
|
||||
console.error("api.user.profile validation error")
|
||||
console.error("api.user.profile validation error", JSON.stringify({})) // not passing the data to avoid logging sensitive data
|
||||
return null
|
||||
}
|
||||
console.info("api.user.profile success")
|
||||
console.info("api.user.profile success", JSON.stringify({}))
|
||||
return verifiedData
|
||||
}
|
||||
|
||||
@@ -107,7 +112,7 @@ async function updateStaysBookingUrl(
|
||||
lang: Lang
|
||||
) {
|
||||
// Tenporary API call needed till we have user name in ctx session data
|
||||
console.info("api.user.profile start")
|
||||
console.info("api.user.profile start", JSON.stringify({}))
|
||||
const apiResponse = await api.get(api.endpoints.v1.profile, {
|
||||
cache: "no-store",
|
||||
headers: {
|
||||
@@ -144,7 +149,7 @@ async function updateStaysBookingUrl(
|
||||
}
|
||||
|
||||
if (apiResponse.ok) {
|
||||
console.info("api.user.profile success")
|
||||
console.info("api.user.profile success", JSON.stringify({}))
|
||||
const apiJson = await apiResponse.json()
|
||||
if (apiJson.data?.attributes) {
|
||||
return data.map((d) => {
|
||||
@@ -170,7 +175,7 @@ async function updateStaysBookingUrl(
|
||||
})
|
||||
}
|
||||
}
|
||||
console.info("api.user.profile error", JSON.stringify(apiResponse))
|
||||
console.info("api.user.profile error", JSON.stringify({ error: apiResponse }))
|
||||
|
||||
return data
|
||||
}
|
||||
@@ -281,7 +286,10 @@ export const userQueryRouter = router({
|
||||
const params = new URLSearchParams()
|
||||
params.set("limit", "1")
|
||||
|
||||
console.info("api.booking.stays.past start")
|
||||
console.info(
|
||||
"api.booking.stays.past start",
|
||||
JSON.stringify({ query: { params } })
|
||||
)
|
||||
const previousStaysResponse = await api.get(
|
||||
api.endpoints.v1.previousStays,
|
||||
{
|
||||
@@ -294,8 +302,8 @@ export const userQueryRouter = router({
|
||||
|
||||
if (!previousStaysResponse.ok) {
|
||||
console.error(
|
||||
"api.booking.stays.past error ",
|
||||
JSON.stringify(previousStaysResponse)
|
||||
"api.booking.stays.past error",
|
||||
JSON.stringify({ error: previousStaysResponse })
|
||||
)
|
||||
return notLoggedInUserTrackingData
|
||||
}
|
||||
@@ -306,11 +314,11 @@ export const userQueryRouter = router({
|
||||
if (!verifiedPreviousStaysData.success) {
|
||||
console.error(
|
||||
"api.booking.stays.past validation error, ",
|
||||
JSON.stringify(verifiedPreviousStaysData.error)
|
||||
JSON.stringify({ error: verifiedPreviousStaysData.error })
|
||||
)
|
||||
return notLoggedInUserTrackingData
|
||||
}
|
||||
console.info("api.booking.stays.past success")
|
||||
console.info("api.booking.stays.past success", JSON.stringify({}))
|
||||
|
||||
const membership = getMembership(verifiedUserData.data.memberships)
|
||||
|
||||
@@ -345,7 +353,10 @@ export const userQueryRouter = router({
|
||||
if (cursor) {
|
||||
params.offset = cursor
|
||||
}
|
||||
console.info("api.booking.stays.past start")
|
||||
console.info(
|
||||
"api.booking.stays.past start",
|
||||
JSON.stringify({ query: { params: params.toString() } })
|
||||
)
|
||||
|
||||
const apiResponse = await api.get(
|
||||
api.endpoints.v1.previousStays,
|
||||
@@ -370,7 +381,10 @@ export const userQueryRouter = router({
|
||||
// }
|
||||
console.error(
|
||||
"api.booking.stays.past error ",
|
||||
JSON.stringify(apiResponse)
|
||||
JSON.stringify({
|
||||
query: { params: params.toString() },
|
||||
error: apiResponse,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
@@ -381,12 +395,18 @@ export const userQueryRouter = router({
|
||||
if (!verifiedData.success) {
|
||||
console.error(
|
||||
"api.booking.stays.past validation error ",
|
||||
JSON.stringify(verifiedData.error)
|
||||
JSON.stringify({
|
||||
query: { params: params.toString() },
|
||||
error: verifiedData.error,
|
||||
})
|
||||
)
|
||||
|
||||
return null
|
||||
}
|
||||
console.info("api.booking.stays.past success")
|
||||
console.info(
|
||||
"api.booking.stays.past success",
|
||||
JSON.stringify({ query: { params: params.toString() } })
|
||||
)
|
||||
const nextCursor =
|
||||
verifiedData.data.links &&
|
||||
verifiedData.data.links.offset < verifiedData.data.links.totalCount
|
||||
@@ -414,7 +434,10 @@ export const userQueryRouter = router({
|
||||
if (cursor) {
|
||||
params.offset = cursor
|
||||
}
|
||||
console.info("api.booking.stays.future start")
|
||||
console.info(
|
||||
"api.booking.stays.future start",
|
||||
JSON.stringify({ query: { params: params.toString() } })
|
||||
)
|
||||
const apiResponse = await api.get(
|
||||
api.endpoints.v1.upcomingStays,
|
||||
{
|
||||
@@ -438,7 +461,10 @@ export const userQueryRouter = router({
|
||||
// }
|
||||
console.error(
|
||||
"api.booking.stays.future error ",
|
||||
JSON.stringify(apiResponse)
|
||||
JSON.stringify({
|
||||
query: { params: params.toString() },
|
||||
error: apiResponse,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
@@ -448,11 +474,16 @@ export const userQueryRouter = router({
|
||||
if (!verifiedData.success) {
|
||||
console.error(
|
||||
"api.booking.stays.future validation error ",
|
||||
JSON.stringify(verifiedData.error)
|
||||
JSON.stringify({
|
||||
query: { params: params.toString() },
|
||||
error: verifiedData.error,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
console.info("api.booking.stays.future success")
|
||||
console.info("api.booking.stays.future success", {
|
||||
query: { params: params.toString() },
|
||||
})
|
||||
const nextCursor =
|
||||
verifiedData.data.links &&
|
||||
verifiedData.data.links.offset < verifiedData.data.links.totalCount
|
||||
@@ -476,7 +507,10 @@ export const userQueryRouter = router({
|
||||
.input(friendTransactionsInput)
|
||||
.query(async ({ ctx, input }) => {
|
||||
const { limit, page } = input
|
||||
console.info("api.transaction.friendTransactions start")
|
||||
console.info(
|
||||
"api.transaction.friendTransactions start",
|
||||
JSON.stringify({})
|
||||
)
|
||||
const apiResponse = await api.get(api.endpoints.v1.friendTransactions, {
|
||||
cache: undefined, // override defaultOptions
|
||||
headers: {
|
||||
@@ -498,7 +532,7 @@ export const userQueryRouter = router({
|
||||
// }
|
||||
console.error(
|
||||
"api.transaction.friendTransactions error ",
|
||||
JSON.stringify(apiResponse)
|
||||
JSON.stringify({ error: apiResponse })
|
||||
)
|
||||
return null
|
||||
}
|
||||
@@ -508,12 +542,15 @@ export const userQueryRouter = router({
|
||||
if (!verifiedData.success) {
|
||||
console.error(
|
||||
"api.transaction.friendTransactions validation error ",
|
||||
JSON.stringify(verifiedData.error)
|
||||
JSON.stringify({ error: verifiedData.error })
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
||||
console.info("api.transaction.friendTransactions success")
|
||||
console.info(
|
||||
"api.transaction.friendTransactions success",
|
||||
JSON.stringify({})
|
||||
)
|
||||
const updatedData = await updateStaysBookingUrl(
|
||||
verifiedData.data.data,
|
||||
ctx.session.token.access_token,
|
||||
@@ -580,7 +617,7 @@ export const userQueryRouter = router({
|
||||
}),
|
||||
|
||||
creditCards: protectedProcedure.query(async function ({ ctx }) {
|
||||
console.info("api.profile.creditCards start")
|
||||
console.info("api.profile.creditCards start", JSON.stringify({}))
|
||||
const apiResponse = await api.get(api.endpoints.v1.creditCards, {
|
||||
cache: "no-store",
|
||||
headers: {
|
||||
@@ -591,7 +628,7 @@ export const userQueryRouter = router({
|
||||
if (!apiResponse.ok) {
|
||||
console.error(
|
||||
"api.profile.creditCards error ",
|
||||
JSON.stringify(apiResponse)
|
||||
JSON.stringify({ error: apiResponse })
|
||||
)
|
||||
return null
|
||||
}
|
||||
@@ -601,16 +638,16 @@ export const userQueryRouter = router({
|
||||
if (!verifiedData.success) {
|
||||
console.error(
|
||||
"api.profile.creditCards validation error ",
|
||||
JSON.stringify(verifiedData.error)
|
||||
JSON.stringify({ error: verifiedData.error })
|
||||
)
|
||||
return null
|
||||
}
|
||||
console.info("api.profile.creditCards success")
|
||||
console.info("api.profile.creditCards success", JSON.stringify({}))
|
||||
return verifiedData.data.data
|
||||
}),
|
||||
|
||||
membershipCards: protectedProcedure.query(async function ({ ctx }) {
|
||||
console.info("api.profile start")
|
||||
console.info("api.profile start", JSON.stringify({}))
|
||||
const apiResponse = await api.get(api.endpoints.v1.profile, {
|
||||
cache: "no-store",
|
||||
headers: {
|
||||
@@ -629,7 +666,7 @@ export const userQueryRouter = router({
|
||||
// default:
|
||||
// throw internalServerError()
|
||||
// }
|
||||
console.log("api.profile error ", JSON.stringify(apiResponse))
|
||||
console.log("api.profile error", JSON.stringify({ error: apiResponse }))
|
||||
}
|
||||
|
||||
const apiJson = await apiResponse.json()
|
||||
@@ -640,12 +677,12 @@ export const userQueryRouter = router({
|
||||
|
||||
if (!verifiedData.success) {
|
||||
console.error(
|
||||
"api.profile validation error ",
|
||||
JSON.stringify(verifiedData)
|
||||
"api.profile validation error",
|
||||
JSON.stringify({ error: verifiedData })
|
||||
)
|
||||
return null
|
||||
}
|
||||
console.info("api.profile success")
|
||||
console.info("api.profile success", JSON.stringify({}))
|
||||
const cards = getMembershipCards(verifiedData.data)
|
||||
|
||||
return cards
|
||||
|
||||
Reference in New Issue
Block a user