/* * 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 ForbiddenCode = { Forbidden: "forbidden", } as const; /** * A short code indicating the error code returned. */ export type ForbiddenCode = ClosedEnum; export type ForbiddenError = { /** * A short code indicating the error code returned. */ code: ForbiddenCode; /** * 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 client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client's identity is known to the server. */ export type ForbiddenData = { error: ForbiddenError; }; /** * The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client's identity is known to the server. */ export class Forbidden extends DubError { error: ForbiddenError; /** The original data that was passed to this error instance. */ data$: ForbiddenData; constructor( err: ForbiddenData, 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 = "Forbidden"; } } /** @internal */ export const ForbiddenCode$inboundSchema: z.ZodNativeEnum< typeof ForbiddenCode > = z.nativeEnum(ForbiddenCode); /** @internal */ export const ForbiddenError$inboundSchema: z.ZodType< ForbiddenError, z.ZodTypeDef, unknown > = z.object({ code: ForbiddenCode$inboundSchema, message: z.string(), doc_url: z.string().optional(), }).transform((v) => { return remap$(v, { "doc_url": "docUrl", }); }); export function forbiddenErrorFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => ForbiddenError$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'ForbiddenError' from JSON`, ); } /** @internal */ export const Forbidden$inboundSchema: z.ZodType< Forbidden, z.ZodTypeDef, unknown > = z.object({ error: z.lazy(() => ForbiddenError$inboundSchema), request$: z.instanceof(Request), response$: z.instanceof(Response), body$: z.string(), }) .transform((v) => { return new Forbidden(v, { request: v.request$, response: v.response$, body: v.body$, }); });