/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod"; import { remap as remap$ } from "../../lib/primitives.js"; import * as components from "../components/index.js"; /** * HTTP error response model. */ export type HTTPErrorData = { /** * Detailed error information. */ detail: components.APIError; /** * Raw HTTP response; suitable for custom response parsing */ rawResponse?: Response | undefined; }; /** * HTTP error response model. */ export class HTTPError extends Error { /** * Detailed error information. */ detail: components.APIError; /** * Raw HTTP response; suitable for custom response parsing */ rawResponse?: Response | undefined; /** The original data that was passed to this error instance. */ data$: HTTPErrorData; constructor(err: HTTPErrorData) { const message = "message" in err && typeof err.message === "string" ? err.message : `API error occurred: ${JSON.stringify(err)}`; super(message); this.data$ = err; this.detail = err.detail; if (err.rawResponse != null) this.rawResponse = err.rawResponse; this.name = "HTTPError"; } } /** @internal */ export const HTTPError$inboundSchema: z.ZodType< HTTPError, z.ZodTypeDef, unknown > = z.object({ detail: components.APIError$inboundSchema, RawResponse: z.instanceof(Response).optional(), }) .transform((v) => { const remapped = remap$(v, { "RawResponse": "rawResponse", }); return new HTTPError(remapped); }); /** @internal */ export type HTTPError$Outbound = { detail: components.APIError$Outbound; RawResponse?: never | undefined; }; /** @internal */ export const HTTPError$outboundSchema: z.ZodType< HTTPError$Outbound, z.ZodTypeDef, HTTPError > = z.instanceof(HTTPError) .transform(v => v.data$) .pipe( z.object({ detail: components.APIError$outboundSchema, rawResponse: z.instanceof(Response).transform(() => { throw new Error("Response cannot be serialized"); }).optional(), }).transform((v) => { return remap$(v, { rawResponse: "RawResponse", }); }), ); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace HTTPError$ { /** @deprecated use `HTTPError$inboundSchema` instead. */ export const inboundSchema = HTTPError$inboundSchema; /** @deprecated use `HTTPError$outboundSchema` instead. */ export const outboundSchema = HTTPError$outboundSchema; /** @deprecated use `HTTPError$Outbound` instead. */ export type Outbound = HTTPError$Outbound; }