/* * 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 { OutpostError } from "./outposterror.js"; import { SDKValidationError } from "./sdkvalidationerror.js"; /** * Additional error details. For validation errors, this is an array of human-readable messages. */ export type Data = Array | { [k: string]: any }; /** * Standard error response format. */ export type APIErrorResponseData = { /** * HTTP status code. */ status?: number | undefined; /** * Human-readable error message. */ message?: string | undefined; /** * Additional error details. For validation errors, this is an array of human-readable messages. */ data?: Array | { [k: string]: any } | undefined; }; /** * Standard error response format. */ export class APIErrorResponse extends OutpostError { /** * HTTP status code. */ status?: number | undefined; /** * Additional error details. For validation errors, this is an array of human-readable messages. */ data?: Array | { [k: string]: any } | undefined; /** The original data that was passed to this error instance. */ data$: APIErrorResponseData; constructor( err: APIErrorResponseData, httpMeta: { response: Response; request: Request; body: string }, ) { const message = err.message || `API error occurred: ${JSON.stringify(err)}`; super(message, httpMeta); this.data$ = err; if (err.status != null) this.status = err.status; if (err.data != null) this.data = err.data; this.name = "APIErrorResponse"; } } /** @internal */ export const Data$inboundSchema: z.ZodType = z .union([z.array(z.string()), z.record(z.any())]); /** @internal */ export type Data$Outbound = Array | { [k: string]: any }; /** @internal */ export const Data$outboundSchema: z.ZodType< Data$Outbound, z.ZodTypeDef, unknown > = z.union([z.array(z.string()), z.record(z.any())]); export function dataToJSON(data: Data): string { return JSON.stringify(Data$outboundSchema.parse(data)); } export function dataFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Data$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Data' from JSON`, ); } /** @internal */ export const APIErrorResponse$inboundSchema: z.ZodType< APIErrorResponse, z.ZodTypeDef, unknown > = z.object({ status: z.number().int().optional(), message: z.string().optional(), data: z.union([z.array(z.string()), z.record(z.any())]).optional(), request$: z.instanceof(Request), response$: z.instanceof(Response), body$: z.string(), }) .transform((v) => { return new APIErrorResponse(v, { request: v.request$, response: v.response$, body: v.body$, }); }); /** @internal */ export type APIErrorResponse$Outbound = { status?: number | undefined; message?: string | undefined; data?: Array | { [k: string]: any } | undefined; }; /** @internal */ export const APIErrorResponse$outboundSchema: z.ZodType< APIErrorResponse$Outbound, z.ZodTypeDef, APIErrorResponse > = z.instanceof(APIErrorResponse) .transform(v => v.data$) .pipe(z.object({ status: z.number().int().optional(), message: z.string().optional(), data: z.union([z.array(z.string()), z.record(z.any())]).optional(), }));