/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. * @generated-id: 7d1b393d1130 */ import * as z from "zod/v4"; import { AlienError } from "./alienerror.js"; export type APIErrorData = { /** * A unique identifier for the type of error. * * @remarks * * This should be a short, machine-readable string that can be used * by clients to programmatically handle different error types. * Examples: "NOT_FOUND", "VALIDATION_ERROR", "TIMEOUT" */ code: string; /** * Human-readable error message. * * @remarks * * This message should be clear and actionable for developers or end-users, * providing context about what went wrong and potentially how to fix it. */ message: string; /** * The underlying error that caused this error, creating an error chain. * * @remarks * * This allows for proper error propagation and debugging by maintaining * the full context of how an error occurred through multiple layers * of an application. */ source?: any | null | undefined; /** * Indicates whether the operation that caused the error should be retried. * * @remarks * * When `true`, the error is transient and the operation might succeed * if attempted again. When `false`, retrying the same operation is * unlikely to succeed without changes. */ retryable?: boolean | undefined; /** * Additional diagnostic information about the error context. * * @remarks * * This optional field can contain structured data providing more details * about the error, such as validation errors, request parameters that * caused the issue, or other relevant context information. */ context?: any | null | undefined; /** * Optional human-facing remediation hint. */ hint?: string | null | undefined; /** * HTTP status code for this error. * * @remarks * * Used when converting the error to an HTTP response. If None, falls back to * the error type's default status code or 500. */ httpStatusCode?: number | null | undefined; /** * Indicates if this is an internal error that should not be exposed to users. * * @remarks * * When `true`, this error contains sensitive information or implementation * details that should not be shown to end-users. Such errors should be * logged for debugging but replaced with generic error messages in responses. */ internal: boolean; /** * Request ID echoed in the x-request-id response header and server logs. */ requestId?: string | undefined; }; export class APIError extends AlienError { /** * A unique identifier for the type of error. * * @remarks * * This should be a short, machine-readable string that can be used * by clients to programmatically handle different error types. * Examples: "NOT_FOUND", "VALIDATION_ERROR", "TIMEOUT" */ code: string; /** * The underlying error that caused this error, creating an error chain. * * @remarks * * This allows for proper error propagation and debugging by maintaining * the full context of how an error occurred through multiple layers * of an application. */ source?: any | null | undefined; /** * Indicates whether the operation that caused the error should be retried. * * @remarks * * When `true`, the error is transient and the operation might succeed * if attempted again. When `false`, retrying the same operation is * unlikely to succeed without changes. */ retryable?: boolean | undefined; /** * Additional diagnostic information about the error context. * * @remarks * * This optional field can contain structured data providing more details * about the error, such as validation errors, request parameters that * caused the issue, or other relevant context information. */ context?: any | null | undefined; /** * Optional human-facing remediation hint. */ hint?: string | null | undefined; /** * HTTP status code for this error. * * @remarks * * Used when converting the error to an HTTP response. If None, falls back to * the error type's default status code or 500. */ httpStatusCode?: number | null | undefined; /** * Indicates if this is an internal error that should not be exposed to users. * * @remarks * * When `true`, this error contains sensitive information or implementation * details that should not be shown to end-users. Such errors should be * logged for debugging but replaced with generic error messages in responses. */ internal: boolean; /** * Request ID echoed in the x-request-id response header and server logs. */ requestId?: string | undefined; /** The original data that was passed to this error instance. */ data$: APIErrorData; constructor( err: APIErrorData, httpMeta: { response: Response; request: Request; body: string }, ) { const message = err.message || `API error occurred: ${JSON.stringify(err)}`; super(message, httpMeta); this.data$ = err; this.code = err.code; if (err.source != null) this.source = err.source; if (err.retryable != null) this.retryable = err.retryable; if (err.context != null) this.context = err.context; if (err.hint != null) this.hint = err.hint; if (err.httpStatusCode != null) this.httpStatusCode = err.httpStatusCode; this.internal = err.internal; if (err.requestId != null) this.requestId = err.requestId; this.name = "APIError"; } } /** @internal */ export const APIError$inboundSchema: z.ZodType = z.object({ code: z.string(), message: z.string(), source: z.nullable(z.any()).optional(), retryable: z.boolean().default(false), context: z.nullable(z.any()).optional(), hint: z.nullable(z.string()).optional(), httpStatusCode: z.nullable(z.int()).optional(), internal: z.boolean(), requestId: z.string().optional(), request$: z.custom(x => x instanceof Request), response$: z.custom(x => x instanceof Response), body$: z.string(), }) .transform((v) => { return new APIError(v, { request: v.request$, response: v.response$, body: v.body$, }); });