fix: add apiResponse.text() to logging
This commit is contained in:
committed by
Michael Zetterberg
parent
7cd6367c15
commit
9497e8eef3
@@ -46,10 +46,10 @@ export async function request<T>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const print = (await import("graphql/language/printer")).print
|
// const print = (await import("graphql/language/printer")).print
|
||||||
const nr = Math.random()
|
// const nr = Math.random()
|
||||||
console.log(`START REQUEST ${nr}`)
|
// console.log(`START REQUEST ${nr}`)
|
||||||
console.time(`OUTGOING REQUEST ${nr}`)
|
// console.time(`OUTGOING REQUEST ${nr}`)
|
||||||
// console.log(`Sending reqeust to ${env.CMS_URL}`)
|
// console.log(`Sending reqeust to ${env.CMS_URL}`)
|
||||||
// console.log(`Query:`, print(query as DocumentNode))
|
// console.log(`Query:`, print(query as DocumentNode))
|
||||||
// console.log(`Variables:`, variables)
|
// console.log(`Variables:`, variables)
|
||||||
@@ -63,7 +63,7 @@ export async function request<T>(
|
|||||||
variables,
|
variables,
|
||||||
})
|
})
|
||||||
|
|
||||||
console.timeEnd(`OUTGOING REQUEST ${nr}`)
|
// console.timeEnd(`OUTGOING REQUEST ${nr}`)
|
||||||
// console.log({ response })
|
// console.log({ response })
|
||||||
|
|
||||||
return { data: response }
|
return { data: response }
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import { error } from "console"
|
|
||||||
|
|
||||||
import { GetContactConfig } from "@/lib/graphql/Query/ContactConfig.graphql"
|
import { GetContactConfig } from "@/lib/graphql/Query/ContactConfig.graphql"
|
||||||
import {
|
import {
|
||||||
GetCurrentFooter,
|
GetCurrentFooter,
|
||||||
@@ -11,11 +9,7 @@ import {
|
|||||||
} from "@/lib/graphql/Query/CurrentHeader.graphql"
|
} from "@/lib/graphql/Query/CurrentHeader.graphql"
|
||||||
import { request } from "@/lib/graphql/request"
|
import { request } from "@/lib/graphql/request"
|
||||||
import { notFound } from "@/server/errors/trpc"
|
import { notFound } from "@/server/errors/trpc"
|
||||||
import {
|
import { contentstackBaseProcedure, router } from "@/server/trpc"
|
||||||
contentstackBaseProcedure,
|
|
||||||
publicProcedure,
|
|
||||||
router,
|
|
||||||
} from "@/server/trpc"
|
|
||||||
|
|
||||||
import { generateTag } from "@/utils/generateTag"
|
import { generateTag } from "@/utils/generateTag"
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import { error } from "console"
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
GetNavigationMyPages,
|
GetNavigationMyPages,
|
||||||
GetNavigationMyPagesRefs,
|
GetNavigationMyPagesRefs,
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ export const hotelQueryRouter = router({
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (!apiResponse.ok) {
|
if (!apiResponse.ok) {
|
||||||
|
const text = await apiResponse.text()
|
||||||
console.error(
|
console.error(
|
||||||
"api.hotels.hotel error",
|
"api.hotels.hotel error",
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
@@ -57,6 +58,7 @@ export const hotelQueryRouter = router({
|
|||||||
error: {
|
error: {
|
||||||
status: apiResponse.status,
|
status: apiResponse.status,
|
||||||
statusText: apiResponse.statusText,
|
statusText: apiResponse.statusText,
|
||||||
|
text,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ export const userMutationRouter = router({
|
|||||||
ctx,
|
ctx,
|
||||||
input,
|
input,
|
||||||
}) {
|
}) {
|
||||||
|
console.info(
|
||||||
|
"api.user.creditCard.add start",
|
||||||
|
JSON.stringify({ query: { language: input.language } })
|
||||||
|
)
|
||||||
const apiResponse = await api.post(api.endpoints.v1.intiateSaveCard, {
|
const apiResponse = await api.post(api.endpoints.v1.intiateSaveCard, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${ctx.session.token.access_token}`,
|
Authorization: `Bearer ${ctx.session.token.access_token}`,
|
||||||
@@ -26,24 +30,43 @@ export const userMutationRouter = router({
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (!apiResponse.ok) {
|
if (!apiResponse.ok) {
|
||||||
console.info(`API Response Failed - Initiating add Creadit Card flow`)
|
const text = await apiResponse.text()
|
||||||
console.error(apiResponse)
|
console.error(
|
||||||
|
"api.user.creditCard.add error",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { language: input.language },
|
||||||
|
error: {
|
||||||
|
status: apiResponse.status,
|
||||||
|
statusText: apiResponse.statusText,
|
||||||
|
error: text,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
const apiJson = await apiResponse.json()
|
const apiJson = await apiResponse.json()
|
||||||
const verifiedData = initiateSaveCardSchema.safeParse(apiJson)
|
const verifiedData = initiateSaveCardSchema.safeParse(apiJson)
|
||||||
if (!verifiedData.success) {
|
if (!verifiedData.success) {
|
||||||
console.error(`Failed to initiate save card data`)
|
console.error(
|
||||||
console.error(verifiedData.error)
|
"api.user.creditCard.add validation error",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { language: input.language },
|
||||||
|
error: verifiedData.error,
|
||||||
|
})
|
||||||
|
)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
console.info(
|
||||||
|
"api.user.creditCard.add success",
|
||||||
|
JSON.stringify({ query: { language: input.language } })
|
||||||
|
)
|
||||||
return verifiedData.data.data
|
return verifiedData.data.data
|
||||||
}),
|
}),
|
||||||
save: protectedProcedure
|
save: protectedProcedure
|
||||||
.input(saveCreditCardInput)
|
.input(saveCreditCardInput)
|
||||||
.mutation(async function ({ ctx, input }) {
|
.mutation(async function ({ ctx, input }) {
|
||||||
|
console.info("api.user.creditCard.save start", JSON.stringify({}))
|
||||||
const apiResponse = await api.post(
|
const apiResponse = await api.post(
|
||||||
`${api.endpoints.v1.creditCards}/${input.transactionId}`,
|
`${api.endpoints.v1.creditCards}/${input.transactionId}`,
|
||||||
{
|
{
|
||||||
@@ -54,16 +77,29 @@ export const userMutationRouter = router({
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (!apiResponse.ok) {
|
if (!apiResponse.ok) {
|
||||||
console.error(`API Response Failed - Save card`)
|
const text = await apiResponse.text()
|
||||||
console.error(apiResponse)
|
console.error(
|
||||||
|
"api.user.creditCard.save error",
|
||||||
|
JSON.stringify({
|
||||||
|
error: {
|
||||||
|
status: apiResponse.status,
|
||||||
|
statusText: apiResponse.statusText,
|
||||||
|
text,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
console.info("api.user.creditCard.save success", JSON.stringify({}))
|
||||||
return true
|
return true
|
||||||
}),
|
}),
|
||||||
delete: protectedProcedure
|
delete: protectedProcedure
|
||||||
.input(deleteCreditCardInput)
|
.input(deleteCreditCardInput)
|
||||||
.mutation(async function ({ ctx, input }) {
|
.mutation(async function ({ ctx, input }) {
|
||||||
|
console.info(
|
||||||
|
"api.user.creditCard.delete start",
|
||||||
|
JSON.stringify({ query: {} })
|
||||||
|
)
|
||||||
const apiResponse = await api.remove(
|
const apiResponse = await api.remove(
|
||||||
`${api.endpoints.v1.creditCards}/${input.creditCardId}`,
|
`${api.endpoints.v1.creditCards}/${input.creditCardId}`,
|
||||||
{
|
{
|
||||||
@@ -74,11 +110,21 @@ export const userMutationRouter = router({
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (!apiResponse.ok) {
|
if (!apiResponse.ok) {
|
||||||
console.error(`API Response Failed - Delete credit card`)
|
const text = await apiResponse.text()
|
||||||
console.error(apiResponse)
|
console.error(
|
||||||
|
"api.user.creditCard.delete error",
|
||||||
|
JSON.stringify({
|
||||||
|
error: {
|
||||||
|
status: apiResponse.status,
|
||||||
|
statusText: apiResponse.statusText,
|
||||||
|
text,
|
||||||
|
},
|
||||||
|
query: {},
|
||||||
|
})
|
||||||
|
)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
console.info("api.user.creditCard.delete success", JSON.stringify({}))
|
||||||
return true
|
return true
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -51,12 +51,14 @@ async function getVerifiedUser({ session }: { session: Session }) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (!apiResponse.ok) {
|
if (!apiResponse.ok) {
|
||||||
|
const text = await apiResponse.text()
|
||||||
console.error(
|
console.error(
|
||||||
"api.user.profile error",
|
"api.user.profile error",
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
error: {
|
error: {
|
||||||
status: apiResponse.status,
|
status: apiResponse.status,
|
||||||
statusText: apiResponse.statusText,
|
statusText: apiResponse.statusText,
|
||||||
|
text,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@@ -387,6 +389,7 @@ export const userQueryRouter = router({
|
|||||||
// default:
|
// default:
|
||||||
// throw internalServerError(apiResponse)
|
// throw internalServerError(apiResponse)
|
||||||
// }
|
// }
|
||||||
|
const text = await apiResponse.text()
|
||||||
console.error(
|
console.error(
|
||||||
"api.booking.stays.past error ",
|
"api.booking.stays.past error ",
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
@@ -394,6 +397,7 @@ export const userQueryRouter = router({
|
|||||||
error: {
|
error: {
|
||||||
status: apiResponse.status,
|
status: apiResponse.status,
|
||||||
statusText: apiResponse.statusText,
|
statusText: apiResponse.statusText,
|
||||||
|
text,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@@ -470,6 +474,7 @@ export const userQueryRouter = router({
|
|||||||
// default:
|
// default:
|
||||||
// throw internalServerError(apiResponse)
|
// throw internalServerError(apiResponse)
|
||||||
// }
|
// }
|
||||||
|
const text = await apiResponse.text()
|
||||||
console.error(
|
console.error(
|
||||||
"api.booking.stays.future error ",
|
"api.booking.stays.future error ",
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
@@ -477,6 +482,7 @@ export const userQueryRouter = router({
|
|||||||
error: {
|
error: {
|
||||||
status: apiResponse.status,
|
status: apiResponse.status,
|
||||||
statusText: apiResponse.statusText,
|
statusText: apiResponse.statusText,
|
||||||
|
text,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@@ -544,12 +550,14 @@ export const userQueryRouter = router({
|
|||||||
// default:
|
// default:
|
||||||
// throw internalServerError()
|
// throw internalServerError()
|
||||||
// }
|
// }
|
||||||
|
const text = await apiResponse.text()
|
||||||
console.error(
|
console.error(
|
||||||
"api.transaction.friendTransactions error ",
|
"api.transaction.friendTransactions error ",
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
error: {
|
error: {
|
||||||
status: apiResponse.status,
|
status: apiResponse.status,
|
||||||
statusText: apiResponse.statusText,
|
statusText: apiResponse.statusText,
|
||||||
|
text,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@@ -645,12 +653,14 @@ export const userQueryRouter = router({
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (!apiResponse.ok) {
|
if (!apiResponse.ok) {
|
||||||
|
const text = await apiResponse.text()
|
||||||
console.error(
|
console.error(
|
||||||
"api.profile.creditCards error ",
|
"api.profile.creditCards error ",
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
error: {
|
error: {
|
||||||
status: apiResponse.status,
|
status: apiResponse.status,
|
||||||
statusText: apiResponse.statusText,
|
statusText: apiResponse.statusText,
|
||||||
|
text,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@@ -690,7 +700,17 @@ export const userQueryRouter = router({
|
|||||||
// default:
|
// default:
|
||||||
// throw internalServerError()
|
// throw internalServerError()
|
||||||
// }
|
// }
|
||||||
console.log("api.profile error", JSON.stringify({ error: apiResponse }))
|
const text = await apiResponse.text()
|
||||||
|
console.log(
|
||||||
|
"api.profile error",
|
||||||
|
JSON.stringify({
|
||||||
|
error: {
|
||||||
|
status: apiResponse.status,
|
||||||
|
statusText: apiResponse.statusText,
|
||||||
|
text,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const apiJson = await apiResponse.json()
|
const apiJson = await apiResponse.json()
|
||||||
|
|||||||
Reference in New Issue
Block a user