/* * 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 { collectExtraKeys as collectExtraKeys$, lazySchema as lazySchema$, 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"; export type Error2 = { reason?: string | undefined; error?: string | undefined; }; /** * Why the operation is unsupported. Absent when there is no reason to give (the connector does not implement the operation). A string when the connector states a reason. An object `{ reason, error }` when a batch request is refused: `reason` is a stable code, `error` a human-readable explanation. */ export type ErrorT = string | Error2; /** * Which operation the connector does not support, and why. */ export type MethodNotAllowedResponseDetail = { /** * The unsupported unified operation and connector. */ context?: string | undefined; /** * Why the operation is unsupported. Absent when there is no reason to give (the connector does not implement the operation). A string when the connector states a reason. An object `{ reason, error }` when a batch request is refused: `reason` is a stable code, `error` a human-readable explanation. */ error?: string | Error2 | undefined; additionalProperties?: { [k: string]: any } | undefined; }; /** * The connector cannot serve this operation. No request was sent to the connector, and retrying will not help. The `Allow` header lists the methods the connector does serve on the same URL. */ export type MethodNotAllowedResponseData = { /** * 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; /** * Which operation the connector does not support, and why. */ detail?: MethodNotAllowedResponseDetail | undefined; /** * Link to documentation of error type */ ref?: string | undefined; }; /** * The connector cannot serve this operation. No request was sent to the connector, and retrying will not help. The `Allow` header lists the methods the connector does serve on the same URL. */ export class MethodNotAllowedResponse 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; /** * Which operation the connector does not support, and why. */ detail?: MethodNotAllowedResponseDetail | undefined; /** * Link to documentation of error type */ ref?: string | undefined; /** The original data that was passed to this error instance. */ data$: MethodNotAllowedResponseData; constructor( err: MethodNotAllowedResponseData, 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; this.name = "MethodNotAllowedResponse"; } } /** @internal */ export const Error2$inboundSchema: z.ZodType = /* @__PURE__ */ lazySchema$(() => z.object({ reason: types.optional(types.string()), error: types.optional(types.string()), }) ); export function error2FromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Error2$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Error2' from JSON`, ); } /** @internal */ export const ErrorT$inboundSchema: z.ZodType = /* @__PURE__ */ lazySchema$(() => smartUnion([types.string(), z.lazy(() => Error2$inboundSchema)]) ); 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 MethodNotAllowedResponseDetail$inboundSchema: z.ZodType< MethodNotAllowedResponseDetail, z.ZodTypeDef, unknown > = /* @__PURE__ */ lazySchema$(() => collectExtraKeys$( z.object({ context: types.optional(types.string()), error: types.optional( smartUnion([types.string(), z.lazy(() => Error2$inboundSchema)]), ), }).catchall(z.any()), "additionalProperties", true, ) ); export function methodNotAllowedResponseDetailFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => MethodNotAllowedResponseDetail$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'MethodNotAllowedResponseDetail' from JSON`, ); } /** @internal */ export const MethodNotAllowedResponse$inboundSchema: z.ZodType< MethodNotAllowedResponse, z.ZodTypeDef, unknown > = /* @__PURE__ */ lazySchema$(() => 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( z.lazy(() => MethodNotAllowedResponseDetail$inboundSchema), ), ref: types.optional(types.string()), request$: z.instanceof(Request), response$: z.instanceof(Response), body$: z.string(), }) .transform((v) => { const remapped = remap$(v, { "status_code": "statusCode", "type_name": "typeName", }); return new MethodNotAllowedResponse(remapped, { request: v.request$, response: v.response$, body: v.body$, }); }) );