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 { cookies } from "next/headers"
|
||||
import { redirect } from "next/navigation"
|
||||
import { z } from "zod"
|
||||
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
import { safeTry } from "@scandic-hotels/common/utils/safeTry"
|
||||
import { SAS_TOKEN_STORAGE_KEY } from "@scandic-hotels/trpc/constants/partnerSAS"
|
||||
|
||||
@@ -35,7 +36,7 @@ export async function GET(
|
||||
})
|
||||
|
||||
if (!result.success) {
|
||||
console.error("[SAS] Invalid search params", result.error)
|
||||
logger.error("[SAS] Invalid search params", result.error)
|
||||
redirect(`/${lang}/sas-x-scandic/error?errorCode=invalid_query`)
|
||||
}
|
||||
const { code, state } = result.data
|
||||
@@ -62,7 +63,7 @@ export async function GET(
|
||||
|
||||
if (!tokenResponse.ok) {
|
||||
const error = await tokenResponse.text()
|
||||
console.error("[SAS] Failed to get token", error)
|
||||
logger.error("[SAS] Failed to get token", error)
|
||||
redirect(`/${lang}/sas-x-scandic/error?errorCode=token_error`)
|
||||
}
|
||||
|
||||
@@ -90,7 +91,7 @@ export async function GET(
|
||||
const caller = await serverClient()
|
||||
const [data, error] = await safeTry(caller.partner.sas.requestOtp())
|
||||
if (!data || error) {
|
||||
console.error("[SAS] Failed to request OTP", error)
|
||||
logger.error("[SAS] Failed to request OTP", error)
|
||||
redirect(`/${lang}/sas-x-scandic/error`)
|
||||
}
|
||||
|
||||
@@ -107,7 +108,7 @@ export async function GET(
|
||||
throw new Error(`Unhandled request OTP status ${data.status}`)
|
||||
}
|
||||
|
||||
console.log("[SAS] Request OTP response", data)
|
||||
logger.debug("[SAS] Request OTP response", data)
|
||||
|
||||
const otpUrl = new URL(
|
||||
`/${lang}/sas-x-scandic/otp`,
|
||||
|
||||
@@ -4,6 +4,7 @@ import * as Sentry from "@sentry/nextjs"
|
||||
import { useEffect } from "react"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
import { Typography } from "@scandic-hotels/design-system/Typography"
|
||||
|
||||
import { GenericError } from "./components/GenericError"
|
||||
@@ -19,7 +20,7 @@ export default function Error({
|
||||
useEffect(() => {
|
||||
if (!error) return
|
||||
|
||||
console.error(error)
|
||||
logger.error("sas-x-scandic", error)
|
||||
Sentry.captureException(error)
|
||||
}, [error])
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import { redirect } from "next/navigation"
|
||||
import { z } from "zod"
|
||||
|
||||
import { myPages } from "@scandic-hotels/common/constants/routes/myPages"
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
import { safeTry } from "@scandic-hotels/common/utils/safeTry"
|
||||
import {
|
||||
SAS_TOKEN_STORAGE_KEY,
|
||||
@@ -173,7 +174,7 @@ async function handleLinkAccount({
|
||||
const caller = await serverClient()
|
||||
const [res, error] = await safeTry(caller.partner.sas.linkAccount())
|
||||
if (!res || error) {
|
||||
console.error("[SAS] link account error", error)
|
||||
logger.error("[SAS] link account error", error)
|
||||
return {
|
||||
url: `/${lang}/sas-x-scandic/error`,
|
||||
}
|
||||
@@ -216,7 +217,7 @@ async function handleUnlinkAccount({
|
||||
const caller = await serverClient()
|
||||
const [res, error] = await safeTry(caller.partner.sas.unlinkAccount())
|
||||
if (!res || error) {
|
||||
console.error("[SAS] unlink account error", error)
|
||||
logger.error("[SAS] unlink account error", error)
|
||||
return {
|
||||
url: `/${lang}/sas-x-scandic/error`,
|
||||
}
|
||||
@@ -266,7 +267,7 @@ async function handleTransferPoints({
|
||||
)
|
||||
|
||||
if (!res || error || res.transferState === "error") {
|
||||
console.error("[SAS] transfer points error", error)
|
||||
logger.error("[SAS] transfer points error", error)
|
||||
return {
|
||||
url: `/${lang}/sas-x-scandic/error`,
|
||||
type: "replace",
|
||||
@@ -274,14 +275,14 @@ async function handleTransferPoints({
|
||||
}
|
||||
|
||||
if (res.transferState === "notLinked") {
|
||||
console.warn("[SAS] transfer points not linked")
|
||||
logger.warn("[SAS] transfer points not linked")
|
||||
return {
|
||||
url: `/${lang}/sas-x-scandic/link`,
|
||||
type: "replace",
|
||||
}
|
||||
}
|
||||
|
||||
console.log("[SAS] transfer points response", res)
|
||||
logger.debug("[SAS] transfer points response", res)
|
||||
|
||||
return {
|
||||
url: `/${lang}/sas-x-scandic/transfer/success?p=${points}`,
|
||||
|
||||
Reference in New Issue
Block a user