-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapierror.ts
More file actions
79 lines (69 loc) · 2.05 KB
/
apierror.ts
File metadata and controls
79 lines (69 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
*/
import * as z from "zod";
import * as components from "../components/index.js";
import { CloudinaryAssetMgmtError } from "./cloudinaryassetmgmterror.js";
export type ApiErrorData = {
error: components.ApiErrorError;
};
export class ApiError extends CloudinaryAssetMgmtError {
error: components.ApiErrorError;
/** 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.error?.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.ZodType<
ApiError,
z.ZodTypeDef,
unknown
> = z.object({
error: z.lazy(() => components.ApiErrorError$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 type ApiError$Outbound = {
error: components.ApiErrorError$Outbound;
};
/** @internal */
export const ApiError$outboundSchema: z.ZodType<
ApiError$Outbound,
z.ZodTypeDef,
ApiError
> = z.instanceof(ApiError)
.transform(v => v.data$)
.pipe(z.object({
error: z.lazy(() => components.ApiErrorError$outboundSchema),
}));
/**
* @internal
* @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
*/
export namespace ApiError$ {
/** @deprecated use `ApiError$inboundSchema` instead. */
export const inboundSchema = ApiError$inboundSchema;
/** @deprecated use `ApiError$outboundSchema` instead. */
export const outboundSchema = ApiError$outboundSchema;
/** @deprecated use `ApiError$Outbound` instead. */
export type Outbound = ApiError$Outbound;
}