/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod"; import { remap as remap$ } from "../../../lib/primitives.js"; import { safeParse } from "../../../lib/schemas.js"; import { Result as SafeParseResult } from "../../../types/fp.js"; import { SDKValidationError } from "./sdkvalidationerror.js"; export type ServerErrorLocation = { file: string; row: number; col: number; }; export type ServerErrorErrors = { code: string; message: string; location?: ServerErrorLocation | undefined; }; /** * Server Error */ export type ServerErrorData = { code: string; message: string; errors?: Array | undefined; decisionId?: string | undefined; }; /** * Server Error */ export class ServerError extends Error { code: string; errors?: Array | undefined; decisionId?: string | undefined; /** The original data that was passed to this error instance. */ data$: ServerErrorData; constructor(err: ServerErrorData) { const message = "message" in err && typeof err.message === "string" ? err.message : `API error occurred: ${JSON.stringify(err)}`; super(message); this.data$ = err; this.code = err.code; if (err.errors != null) this.errors = err.errors; if (err.decisionId != null) this.decisionId = err.decisionId; this.name = "ServerError"; } } /** @internal */ export const ServerErrorLocation$inboundSchema: z.ZodType< ServerErrorLocation, z.ZodTypeDef, unknown > = z.object({ file: z.string(), row: z.number().int(), col: z.number().int(), }); /** @internal */ export type ServerErrorLocation$Outbound = { file: string; row: number; col: number; }; /** @internal */ export const ServerErrorLocation$outboundSchema: z.ZodType< ServerErrorLocation$Outbound, z.ZodTypeDef, ServerErrorLocation > = z.object({ file: z.string(), row: z.number().int(), col: z.number().int(), }); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace ServerErrorLocation$ { /** @deprecated use `ServerErrorLocation$inboundSchema` instead. */ export const inboundSchema = ServerErrorLocation$inboundSchema; /** @deprecated use `ServerErrorLocation$outboundSchema` instead. */ export const outboundSchema = ServerErrorLocation$outboundSchema; /** @deprecated use `ServerErrorLocation$Outbound` instead. */ export type Outbound = ServerErrorLocation$Outbound; } export function serverErrorLocationToJSON( serverErrorLocation: ServerErrorLocation, ): string { return JSON.stringify( ServerErrorLocation$outboundSchema.parse(serverErrorLocation), ); } export function serverErrorLocationFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => ServerErrorLocation$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'ServerErrorLocation' from JSON`, ); } /** @internal */ export const ServerErrorErrors$inboundSchema: z.ZodType< ServerErrorErrors, z.ZodTypeDef, unknown > = z.object({ code: z.string(), message: z.string(), location: z.lazy(() => ServerErrorLocation$inboundSchema).optional(), }); /** @internal */ export type ServerErrorErrors$Outbound = { code: string; message: string; location?: ServerErrorLocation$Outbound | undefined; }; /** @internal */ export const ServerErrorErrors$outboundSchema: z.ZodType< ServerErrorErrors$Outbound, z.ZodTypeDef, ServerErrorErrors > = z.object({ code: z.string(), message: z.string(), location: z.lazy(() => ServerErrorLocation$outboundSchema).optional(), }); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace ServerErrorErrors$ { /** @deprecated use `ServerErrorErrors$inboundSchema` instead. */ export const inboundSchema = ServerErrorErrors$inboundSchema; /** @deprecated use `ServerErrorErrors$outboundSchema` instead. */ export const outboundSchema = ServerErrorErrors$outboundSchema; /** @deprecated use `ServerErrorErrors$Outbound` instead. */ export type Outbound = ServerErrorErrors$Outbound; } export function serverErrorErrorsToJSON( serverErrorErrors: ServerErrorErrors, ): string { return JSON.stringify( ServerErrorErrors$outboundSchema.parse(serverErrorErrors), ); } export function serverErrorErrorsFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => ServerErrorErrors$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'ServerErrorErrors' from JSON`, ); } /** @internal */ export const ServerError$inboundSchema: z.ZodType< ServerError, z.ZodTypeDef, unknown > = z.object({ code: z.string(), message: z.string(), errors: z.array(z.lazy(() => ServerErrorErrors$inboundSchema)).optional(), decision_id: z.string().optional(), }) .transform((v) => { const remapped = remap$(v, { "decision_id": "decisionId", }); return new ServerError(remapped); }); /** @internal */ export type ServerError$Outbound = { code: string; message: string; errors?: Array | undefined; decision_id?: string | undefined; }; /** @internal */ export const ServerError$outboundSchema: z.ZodType< ServerError$Outbound, z.ZodTypeDef, ServerError > = z.instanceof(ServerError) .transform(v => v.data$) .pipe( z.object({ code: z.string(), message: z.string(), errors: z.array(z.lazy(() => ServerErrorErrors$outboundSchema)) .optional(), decisionId: z.string().optional(), }).transform((v) => { return remap$(v, { decisionId: "decision_id", }); }), ); /** * @internal * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module. */ export namespace ServerError$ { /** @deprecated use `ServerError$inboundSchema` instead. */ export const inboundSchema = ServerError$inboundSchema; /** @deprecated use `ServerError$outboundSchema` instead. */ export const outboundSchema = ServerError$outboundSchema; /** @deprecated use `ServerError$Outbound` instead. */ export type Outbound = ServerError$Outbound; }