/* * 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 shared from "../shared/index.js"; import { SDKValidationError } from "./sdkvalidationerror.js"; import { UnstructuredClientError } from "./unstructuredclienterror.js"; export type Detail = Array | string; export type HTTPValidationErrorData = { detail?: Array | string | undefined; }; export class HTTPValidationError extends UnstructuredClientError { detail?: Array | string | undefined; /** The original data that was passed to this error instance. */ data$: HTTPValidationErrorData; constructor( err: HTTPValidationErrorData, 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; if (err.detail != null) this.detail = err.detail; this.name = "HTTPValidationError"; } } /** @internal */ export const Detail$inboundSchema: z.ZodType = z .union([z.array(shared.ValidationError$inboundSchema), z.string()]); /** @internal */ export type Detail$Outbound = Array | string; /** @internal */ export const Detail$outboundSchema: z.ZodType< Detail$Outbound, z.ZodTypeDef, unknown > = z.union([z.array(shared.ValidationError$outboundSchema), z.string()]); export function detailToJSON(detail: Detail): string { return JSON.stringify(Detail$outboundSchema.parse(detail)); } export function detailFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Detail$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Detail' from JSON`, ); } /** @internal */ export const HTTPValidationError$inboundSchema: z.ZodType< HTTPValidationError, z.ZodTypeDef, unknown > = z.object({ detail: z.union([z.array(shared.ValidationError$inboundSchema), z.string()]) .optional(), request$: z.instanceof(Request), response$: z.instanceof(Response), body$: z.string(), }) .transform((v) => { return new HTTPValidationError(v, { request: v.request$, response: v.response$, body: v.body$, }); }); /** @internal */ export type HTTPValidationError$Outbound = { detail?: Array | string | undefined; }; /** @internal */ export const HTTPValidationError$outboundSchema: z.ZodType< HTTPValidationError$Outbound, z.ZodTypeDef, HTTPValidationError > = z.instanceof(HTTPValidationError) .transform(v => v.data$) .pipe(z.object({ detail: z.union([ z.array(shared.ValidationError$outboundSchema), z.string(), ]).optional(), }));