-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: bookings parsing errors (#18200)
- Loading branch information
Showing
5 changed files
with
87 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
apps/api/v2/src/lib/safe-parse/default-responses-booking.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export const defaultBookingResponses = { | ||
name: "unknown", | ||
email: "unknown", | ||
guests: [], | ||
rescheduleReason: "unknown", | ||
}; | ||
|
||
export const defaultBookingMetadata = { videoCallUrl: "unknown" }; | ||
|
||
export const defaultSeatedBookingData = { responses: { name: "unknown", email: "unknown" } }; | ||
|
||
export const defaultSeatedBookingMetadata = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Logger } from "@nestjs/common"; | ||
import { ZodSchema } from "zod"; | ||
|
||
const logger = new Logger("safeParse"); | ||
|
||
export function safeParse<T>(schema: ZodSchema<T>, value: unknown, defaultValue: T): T { | ||
const result = schema.safeParse(value); | ||
if (result.success) { | ||
return result.data; | ||
} else { | ||
const errorStack = new Error().stack; | ||
|
||
logger.error( | ||
`Zod parsing failed.\n` + | ||
`1. Schema: ${schema.description || "UnnamedSchema"}\n` + | ||
`2. Input: ${JSON.stringify(value, null, 2)}\n` + | ||
`3. Zod Error: ${result.error}\n` + | ||
`4. Call Stack: ${errorStack}` | ||
); | ||
|
||
return defaultValue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters