/* * 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 { SDKError } from "./sdkerror.js"; import { SDKValidationError } from "./sdkvalidationerror.js"; export type ErrorT = { message: string; details?: any | null | undefined; }; export type ErrorEnvelopeData = { error: ErrorT; }; export class ErrorEnvelope extends SDKError { error: ErrorT; /** The original data that was passed to this error instance. */ data$: ErrorEnvelopeData; constructor( err: ErrorEnvelopeData, httpMeta: { response: Response; request: Request; body: string }, ) { const message = err.error?.message || `API error occurred: ${JSON.stringify(err)}`; super(message, httpMeta); this.data$ = err; this.error = err.error; this.name = "ErrorEnvelope"; } } /** @internal */ export const ErrorT$inboundSchema: z.ZodType = z .object({ message: z.string(), details: z.nullable(z.any()).optional(), }); /** @internal */ export type ErrorT$Outbound = { message: string; details?: any | null | undefined; }; /** @internal */ export const ErrorT$outboundSchema: z.ZodType< ErrorT$Outbound, z.ZodTypeDef, ErrorT > = z.object({ message: z.string(), details: z.nullable(z.any()).optional(), }); export function errorToJSON(errorT: ErrorT): string { return JSON.stringify(ErrorT$outboundSchema.parse(errorT)); } export function errorFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => ErrorT$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'ErrorT' from JSON`, ); } /** @internal */ export const ErrorEnvelope$inboundSchema: z.ZodType< ErrorEnvelope, z.ZodTypeDef, unknown > = z.object({ error: z.lazy(() => ErrorT$inboundSchema), request$: z.instanceof(Request), response$: z.instanceof(Response), body$: z.string(), }) .transform((v) => { return new ErrorEnvelope(v, { request: v.request$, response: v.response$, body: v.body$, }); }); /** @internal */ export type ErrorEnvelope$Outbound = { error: ErrorT$Outbound; }; /** @internal */ export const ErrorEnvelope$outboundSchema: z.ZodType< ErrorEnvelope$Outbound, z.ZodTypeDef, ErrorEnvelope > = z.instanceof(ErrorEnvelope) .transform(v => v.data$) .pipe(z.object({ error: z.lazy(() => ErrorT$outboundSchema), }));