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:
@@ -2,6 +2,7 @@
|
||||
|
||||
import { TRPCClientError } from "@trpc/client"
|
||||
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
import { SessionExpiredError } from "@scandic-hotels/trpc/errors"
|
||||
import { TrpcProvider as InternalTrpcProvider } from "@scandic-hotels/trpc/Provider"
|
||||
|
||||
@@ -23,7 +24,7 @@ export default function TrpcProvider({
|
||||
onError={(error) => {
|
||||
if (error instanceof TRPCClientError) {
|
||||
const appError: TRPCClientError<AnyTRPCRouter> = error
|
||||
console.log({ appError })
|
||||
logger.error("trpc error", { appError })
|
||||
if (appError.data?.code === "UNAUTHORIZED") {
|
||||
if (appError.data?.cause instanceof SessionExpiredError) {
|
||||
const loginUrl = login[lang]
|
||||
|
||||
@@ -3,6 +3,7 @@ import { cookies, headers } from "next/headers"
|
||||
import { redirect } from "next/navigation"
|
||||
|
||||
import { Lang } from "@scandic-hotels/common/constants/language"
|
||||
import { createLogger } from "@scandic-hotels/common/logger/createLogger"
|
||||
import { createContext } from "@scandic-hotels/trpc/context"
|
||||
import {
|
||||
appServerClient,
|
||||
@@ -50,6 +51,7 @@ export async function createAppContext() {
|
||||
|
||||
configureServerClient(createAppContext)
|
||||
|
||||
const serverClientLogger = createLogger("serverClient")
|
||||
export async function serverClient() {
|
||||
const ctx = await createAppContext()
|
||||
|
||||
@@ -71,17 +73,18 @@ export async function serverClient() {
|
||||
|
||||
if (webviews.includes(fullPathname)) {
|
||||
const redirectUrl = `/${lang}/webview/refresh?returnurl=${encodeURIComponent(fullPathname)}`
|
||||
console.error(
|
||||
serverClientLogger.error(
|
||||
"Unautorized in webview, redirecting to: ",
|
||||
redirectUrl
|
||||
)
|
||||
|
||||
console.log(`[serverClient] onError redirecting to: ${redirectUrl}`)
|
||||
redirect(redirectUrl)
|
||||
}
|
||||
|
||||
const redirectUrl = `${login[lang]}?redirectTo=${encodeURIComponent(`/${lang}/${pathname}`)}`
|
||||
console.log(`[serverClient] onError redirecting to: ${redirectUrl}`)
|
||||
serverClientLogger.error(
|
||||
`[serverClient] onError redirecting to: ${redirectUrl}`
|
||||
)
|
||||
redirect(redirectUrl)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user