/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 */
import * as z from "zod";
import * as components from "../components/index.js";
import { CloudinaryEnvConfigError } from "./cloudinaryenvconfigerror.js";
export class ApiError extends CloudinaryEnvConfigError {
    constructor(err, httpMeta) {
        const message = "message" in err && typeof err.message === "string"
            ? err.message
            : `API error occurred: ${JSON.stringify(err)}`;
        super(message, httpMeta);
        this.data$ = err;
        this.error = err.error;
        this.name = "ApiError";
    }
}
/** @internal */
export const ApiError$inboundSchema = z.object({
    error: z.lazy(() => components.ErrorT$inboundSchema),
    request$: z.instanceof(Request),
    response$: z.instanceof(Response),
    body$: z.string(),
})
    .transform((v) => {
    return new ApiError(v, {
        request: v.request$,
        response: v.response$,
        body: v.body$,
    });
});
/** @internal */
export const ApiError$outboundSchema = z.instanceof(ApiError)
    .transform(v => v.data$)
    .pipe(z.object({
    error: z.lazy(() => components.ErrorT$outboundSchema),
}));
/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export var ApiError$;
(function (ApiError$) {
    /** @deprecated use `ApiError$inboundSchema` instead. */
    ApiError$.inboundSchema = ApiError$inboundSchema;
    /** @deprecated use `ApiError$outboundSchema` instead. */
    ApiError$.outboundSchema = ApiError$outboundSchema;
})(ApiError$ || (ApiError$ = {}));
//# sourceMappingURL=apierror.js.map