/*
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
*/
import * as z from "zod";
import { safeParse } from "../lib/schemas.js";
import { Result as SafeParseResult } from "../types/fp.js";
import { SDKValidationError } from "./errors/sdkvalidationerror.js";
/**
* Often times it is useful to return context specific to the request that caused the error (i.e. a sample of the stack trace or impacted account) in addition to the standard error message.
*/
export type Details = {};
/**
* Instead of utilizing HTTP status codes to describe node errors (which often do not have a good analog), rich errors are returned using this object. Both the code and message fields can be individually used to correctly identify an error. Implementations MUST use unique values for both fields.
*/
export type ErrorT = {
/**
* Code is a network-specific error code. If desired, this code can be equivalent to an HTTP status code.
*/
code: number;
/**
* Message is a network-specific error message. The message MUST NOT change for a given code. In particular, this means that any contextual information should be included in the details field.
*/
message: string;
/**
* Description allows the implementer to optionally provide additional information about an error. In many cases, the content of this field will be a copy-and-paste from existing developer documentation. Description can ONLY be populated with generic information about a particular type of error. It MUST NOT be populated with information about a particular instantiation of an error (use `details` for this). Whereas the content of Error.Message should stay stable across releases, the content of Error.Description will likely change across releases (as implementers improve error documentation). For this reason, the content in this field is not part of any type assertion (unlike Error.Message).
*/
description?: string | undefined;
/**
* An error is retriable if the same request may succeed if submitted again.
*/
retriable: boolean;
/**
* Often times it is useful to return context specific to the request that caused the error (i.e. a sample of the stack trace or impacted account) in addition to the standard error message.
*/
details?: Details | undefined;
};
/** @internal */
export const Details$inboundSchema: z.ZodType<Details, z.ZodTypeDef, unknown> =
z.object({});
/** @internal */
export type Details$Outbound = {};
/** @internal */
export const Details$outboundSchema: z.ZodType<
Details$Outbound,
z.ZodTypeDef,
Details
> = z.object({});
/**
* @internal
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
*/
export namespace Details$ {
/** @deprecated use `Details$inboundSchema` instead. */
export const inboundSchema = Details$inboundSchema;
/** @deprecated use `Details$outboundSchema` instead. */
export const outboundSchema = Details$outboundSchema;
/** @deprecated use `Details$Outbound` instead. */
export type Outbound = Details$Outbound;
}
export function detailsToJSON(details: Details): string {
return JSON.stringify(Details$outboundSchema.parse(details));
}
export function detailsFromJSON(
jsonString: string,
): SafeParseResult<Details, SDKValidationError> {
return safeParse(
jsonString,
(x) => Details$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'Details' from JSON`,
);
}
/** @internal */
export const ErrorT$inboundSchema: z.ZodType<ErrorT, z.ZodTypeDef, unknown> = z
.object({
code: z.number().int(),
message: z.string(),
description: z.string().optional(),
retriable: z.boolean(),
details: z.lazy(() => Details$inboundSchema).optional(),
});
/** @internal */
export type ErrorT$Outbound = {
code: number;
message: string;
description?: string | undefined;
retriable: boolean;
details?: Details$Outbound | undefined;
};
/** @internal */
export const ErrorT$outboundSchema: z.ZodType<
ErrorT$Outbound,
z.ZodTypeDef,
ErrorT
> = z.object({
code: z.number().int(),
message: z.string(),
description: z.string().optional(),
retriable: z.boolean(),
details: z.lazy(() => Details$outboundSchema).optional(),
});
/**
* @internal
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
*/
export namespace ErrorT$ {
/** @deprecated use `ErrorT$inboundSchema` instead. */
export const inboundSchema = ErrorT$inboundSchema;
/** @deprecated use `ErrorT$outboundSchema` instead. */
export const outboundSchema = ErrorT$outboundSchema;
/** @deprecated use `ErrorT$Outbound` instead. */
export type Outbound = ErrorT$Outbound;
}
export function errorToJSON(errorT: ErrorT): string {
return JSON.stringify(ErrorT$outboundSchema.parse(errorT));
}
export function errorFromJSON(
jsonString: string,
): SafeParseResult<ErrorT, SDKValidationError> {
return safeParse(
jsonString,
(x) => ErrorT$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'ErrorT' from JSON`,
);
}