/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; import { remap as remap$ } from "../../lib/primitives.js"; import { safeParse } from "../../lib/schemas.js"; import { ClosedEnum } from "../../types/enums.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { DubError } from "./duberror.js"; import { SDKValidationError } from "./sdkvalidationerror.js"; /** * A short code indicating the error code returned. */ export const Code = { BadRequest: "bad_request", } as const; /** * A short code indicating the error code returned. */ export type Code = ClosedEnum; export type ErrorT = { /** * A short code indicating the error code returned. */ code: Code; /** * A human readable explanation of what went wrong. */ message: string; /** * A link to our documentation with more details about this error code */ docUrl?: string | undefined; }; /** * The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing). */ export type BadRequestData = { error: ErrorT; }; /** * The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing). */ export class BadRequest extends DubError { error: ErrorT; /** The original data that was passed to this error instance. */ data$: BadRequestData; constructor( err: BadRequestData, 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 = "BadRequest"; } } /** @internal */ export const Code$inboundSchema: z.ZodNativeEnum = z.nativeEnum( Code, ); /** @internal */ export const ErrorT$inboundSchema: z.ZodType = z .object({ code: Code$inboundSchema, message: z.string(), doc_url: z.string().optional(), }).transform((v) => { return remap$(v, { "doc_url": "docUrl", }); }); 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 BadRequest$inboundSchema: z.ZodType< BadRequest, 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 BadRequest(v, { request: v.request$, response: v.response$, body: v.body$, }); });