feat: loosen up the zod validations and return null instead of throwing

This commit is contained in:
Simon Emanuelsson
2024-06-07 10:36:23 +02:00
parent 5c50ac060d
commit aca9221ea6
89 changed files with 1117 additions and 821 deletions

View File

@@ -3,7 +3,7 @@ import {
GetAccountPageRefs,
} from "@/lib/graphql/Query/AccountPage.graphql"
import { request } from "@/lib/graphql/request"
import { internalServerError, notFound } from "@/server/errors/trpc"
import { notFound } from "@/server/errors/trpc"
import { contentstackExtendedProcedureUID, router } from "@/server/trpc"
import {
@@ -45,15 +45,14 @@ export const accountPageQueryRouter = router({
throw notFound(refsResponse)
}
// Remove empty objects from a fetched content type. Needed since
// Contentstack returns empty objects for all non queried blocks in modular blocks.
// This is an ongoing support case in Contentstack, ticker number #00031579
const cleanedData = removeEmptyObjects(refsResponse.data)
const validatedAccountPageRefs =
validateAccountPageRefsSchema.safeParse(cleanedData)
if (!validatedAccountPageRefs.success) {
throw internalServerError(validatedAccountPageRefs.error)
console.info(`Failed to validate My Page Refs - (uid: ${uid})`)
console.error(validatedAccountPageRefs.error)
return null
}
const connections = getConnections(validatedAccountPageRefs.data)
@@ -81,7 +80,9 @@ export const accountPageQueryRouter = router({
)
if (!validatedAccountPage.success) {
throw internalServerError(validatedAccountPage.error)
console.info(`Failed to validate Account Page - (uid: ${uid})`)
console.error(validatedAccountPage.error)
return null
}
// TODO: Make returned data nicer