/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; import { safeParse } from "../../lib/schemas.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import * as components from "../components/index.js"; import { NovuError } from "./novuerror.js"; import { SDKValidationError } from "./sdkvalidationerror.js"; export type Message5 = string | number | boolean | { [k: string]: any }; export type Message4 = {}; /** * Value that failed validation */ export type ValidationErrorDtoMessage = | string | number | boolean | Message4 | Array; export type ValidationErrorDtoData = { /** * HTTP status code of the error response. */ statusCode: number; /** * Timestamp of when the error occurred. */ timestamp: string; /** * The path where the error occurred. */ path: string; /** * Value that failed validation */ message?: | string | number | boolean | Message4 | Array | null | undefined; /** * Optional context object for additional error details. */ ctx?: { [k: string]: any } | undefined; /** * Optional unique identifier for the error, useful for tracking using Sentry and * * @remarks * New Relic, only available for 500. */ errorId?: string | undefined; /** * A record of validation errors keyed by field name */ errors: { [k: string]: components.ConstraintValidation }; }; export class ValidationErrorDto extends NovuError { /** * Timestamp of when the error occurred. */ timestamp: string; /** * The path where the error occurred. */ path: string; /** * Optional context object for additional error details. */ ctx?: { [k: string]: any } | undefined; /** * Optional unique identifier for the error, useful for tracking using Sentry and * * @remarks * New Relic, only available for 500. */ errorId?: string | undefined; /** * A record of validation errors keyed by field name */ errors: { [k: string]: components.ConstraintValidation }; /** The original data that was passed to this error instance. */ data$: ValidationErrorDtoData; constructor( err: ValidationErrorDtoData, httpMeta: { response: Response; request: Request; body: string }, ) { const message = "message" in err && typeof err.message === "string" ? err.message : `API error occurred: ${JSON.stringify(err)}`; super(message, httpMeta); this.data$ = err; this.timestamp = err.timestamp; this.path = err.path; if (err.ctx != null) this.ctx = err.ctx; if (err.errorId != null) this.errorId = err.errorId; this.errors = err.errors; this.name = "ValidationErrorDto"; } } /** @internal */ export const Message5$inboundSchema: z.ZodType< Message5, z.ZodTypeDef, unknown > = z.union([z.string(), z.number(), z.boolean(), z.record(z.any())]); export function message5FromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Message5$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Message5' from JSON`, ); } /** @internal */ export const Message4$inboundSchema: z.ZodType< Message4, z.ZodTypeDef, unknown > = z.object({}); export function message4FromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Message4$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Message4' from JSON`, ); } /** @internal */ export const ValidationErrorDtoMessage$inboundSchema: z.ZodType< ValidationErrorDtoMessage, z.ZodTypeDef, unknown > = z.union([ z.string(), z.number(), z.boolean(), z.lazy(() => Message4$inboundSchema), z.array( z.nullable( z.union([z.string(), z.number(), z.boolean(), z.record(z.any())]), ), ), ]); export function validationErrorDtoMessageFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => ValidationErrorDtoMessage$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'ValidationErrorDtoMessage' from JSON`, ); } /** @internal */ export const ValidationErrorDto$inboundSchema: z.ZodType< ValidationErrorDto, z.ZodTypeDef, unknown > = z.object({ statusCode: z.number(), timestamp: z.string(), path: z.string(), message: z.nullable( z.union([ z.string(), z.number(), z.boolean(), z.lazy(() => Message4$inboundSchema), z.array( z.nullable( z.union([z.string(), z.number(), z.boolean(), z.record(z.any())]), ), ), ]), ).optional(), ctx: z.record(z.any()).optional(), errorId: z.string().optional(), errors: z.record(components.ConstraintValidation$inboundSchema), request$: z.instanceof(Request), response$: z.instanceof(Response), body$: z.string(), }) .transform((v) => { return new ValidationErrorDto(v, { request: v.request$, response: v.response$, body: v.body$, }); });