/* * 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 { NovuError } from "./novuerror.js"; import { SDKValidationError } from "./sdkvalidationerror.js"; export type Five = string | number | boolean | { [k: string]: any }; export type Four = {}; /** * Value that failed validation */ export type Message = | string | number | boolean | Four | Array; export type ErrorDtoData = { /** * 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 | Four | 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; }; export class ErrorDto 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; /** The original data that was passed to this error instance. */ data$: ErrorDtoData; constructor( err: ErrorDtoData, 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.name = "ErrorDto"; } } /** @internal */ export const Five$inboundSchema: z.ZodType = z .union([z.string(), z.number(), z.boolean(), z.record(z.any())]); export function fiveFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Five$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Five' from JSON`, ); } /** @internal */ export const Four$inboundSchema: z.ZodType = z .object({}); export function fourFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Four$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Four' from JSON`, ); } /** @internal */ export const Message$inboundSchema: z.ZodType = z.union([ z.string(), z.number(), z.boolean(), z.lazy(() => Four$inboundSchema), z.array( z.nullable( z.union([z.string(), z.number(), z.boolean(), z.record(z.any())]), ), ), ]); export function messageFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Message$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Message' from JSON`, ); } /** @internal */ export const ErrorDto$inboundSchema: z.ZodType< ErrorDto, 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(() => Four$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(), request$: z.instanceof(Request), response$: z.instanceof(Response), body$: z.string(), }) .transform((v) => { return new ErrorDto(v, { request: v.request$, response: v.response$, body: v.body$, }); });