/* * 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 { Result as SafeParseResult } from "../../types/fp.js"; import * as types from "../../types/primitives.js"; import { smartUnion } from "../../types/smartUnion.js"; import { ApideckError } from "./apideckerror.js"; import { SDKValidationError } from "./sdkvalidationerror.js"; /** * Contains parameter or domain specific information related to the error and why it occurred. */ export type Detail = string | { [k: string]: any }; export type DownstreamErrors = { /** * Error message from the downstream provider */ message?: string | undefined; /** * Additional error details */ detail?: string | undefined; /** * Error code from the downstream provider */ code?: string | undefined; }; /** * Bad Request */ export type BadRequestResponseData = { /** * HTTP status code */ statusCode?: number | undefined; /** * Contains an explanation of the status_code as defined in HTTP/1.1 standard (RFC 7231) */ error?: string | undefined; /** * The type of error returned */ typeName?: string | undefined; /** * A human-readable message providing more details about the error. */ message?: string | undefined; /** * Contains parameter or domain specific information related to the error and why it occurred. */ detail?: string | { [k: string]: any } | undefined; /** * Link to documentation of error type */ ref?: string | undefined; /** * Contains downstream errors returned from the connector. Only present when type_name is ConnectorExecutionError. */ downstreamErrors?: Array | undefined; }; /** * Bad Request */ export class BadRequestResponse extends ApideckError { /** * HTTP status code */ statusCode?: number | undefined; /** * Contains an explanation of the status_code as defined in HTTP/1.1 standard (RFC 7231) */ error?: string | undefined; /** * The type of error returned */ typeName?: string | undefined; /** * Contains parameter or domain specific information related to the error and why it occurred. */ detail?: string | { [k: string]: any } | undefined; /** * Link to documentation of error type */ ref?: string | undefined; /** * Contains downstream errors returned from the connector. Only present when type_name is ConnectorExecutionError. */ downstreamErrors?: Array | undefined; /** The original data that was passed to this error instance. */ data$: BadRequestResponseData; constructor( err: BadRequestResponseData, 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.statusCode != null) this.statusCode = err.statusCode; if (err.error != null) this.error = err.error; if (err.typeName != null) this.typeName = err.typeName; if (err.detail != null) this.detail = err.detail; if (err.ref != null) this.ref = err.ref; if (err.downstreamErrors != null) { this.downstreamErrors = err.downstreamErrors; } this.name = "BadRequestResponse"; } } /** @internal */ export const Detail$inboundSchema: z.ZodType = smartUnion([types.string(), z.record(z.any())]); export function detailFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Detail$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Detail' from JSON`, ); } /** @internal */ export const DownstreamErrors$inboundSchema: z.ZodType< DownstreamErrors, z.ZodTypeDef, unknown > = z.object({ message: types.optional(types.string()), detail: types.optional(types.string()), code: types.optional(types.string()), }); export function downstreamErrorsFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => DownstreamErrors$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'DownstreamErrors' from JSON`, ); } /** @internal */ export const BadRequestResponse$inboundSchema: z.ZodType< BadRequestResponse, z.ZodTypeDef, unknown > = z.object({ status_code: types.optional(types.number()), error: types.optional(types.string()), type_name: types.optional(types.string()), message: types.optional(types.string()), detail: types.optional(smartUnion([types.string(), z.record(z.any())])), ref: types.optional(types.string()), downstream_errors: types.optional( z.array(z.lazy(() => DownstreamErrors$inboundSchema)), ), request$: z.instanceof(Request), response$: z.instanceof(Response), body$: z.string(), }) .transform((v) => { const remapped = remap$(v, { "status_code": "statusCode", "type_name": "typeName", "downstream_errors": "downstreamErrors", }); return new BadRequestResponse(remapped, { request: v.request$, response: v.response$, body: v.body$, }); });