Merged in fix/book-453-linkconnection (pull request #2972)
fix(BOOK-453): avoid linkConnection invalid * fix(BOOK-453): avoid linkConnection invalid * test * test * test * Merge master
This commit is contained in:
@@ -19,6 +19,7 @@ import {
|
||||
import {
|
||||
linkRefsUnionSchema,
|
||||
linkUnionSchema,
|
||||
rawLinkUnionSchema,
|
||||
transformPageLink,
|
||||
transformPageLinkRef,
|
||||
} from "../schemas/pageLinks"
|
||||
@@ -410,7 +411,7 @@ const linkSchema = z
|
||||
linkConnection: z.object({
|
||||
edges: z.array(
|
||||
z.object({
|
||||
node: discriminatedUnion(linkUnionSchema.options),
|
||||
node: discriminatedUnion(rawLinkUnionSchema.options),
|
||||
})
|
||||
),
|
||||
}),
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
import * as Sentry from "@sentry/nextjs"
|
||||
import { z } from "zod"
|
||||
|
||||
import { logger } from "@scandic-hotels/common/logger"
|
||||
|
||||
import { getValueFromContactConfig } from "../../../utils/contactConfig"
|
||||
|
||||
import type { Edges } from "../../../types/edges"
|
||||
@@ -95,7 +100,9 @@ export function getSiteConfigConnections(refs: GetSiteConfigRefData) {
|
||||
}
|
||||
node.sidepeek_content.content.embedded_itemsConnection.edges.forEach(
|
||||
({ node }) => {
|
||||
connections.push(node.system)
|
||||
if (node.system) {
|
||||
connections.push(node.system)
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
@@ -120,3 +127,14 @@ export function getAlertPhoneContactData(
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
export const safeUnion = <T extends z.ZodTypeAny>(schema: T) =>
|
||||
z.preprocess((val) => {
|
||||
try {
|
||||
return schema.parse(val)
|
||||
} catch (err) {
|
||||
Sentry.captureException(err)
|
||||
logger.warn("Invalid node in safeUnion", err)
|
||||
return null
|
||||
}
|
||||
}, schema)
|
||||
|
||||
Reference in New Issue
Block a user