Repository navigation
Expand file tree
/
Copy pathconnecterror.ts
More file actions
104 lines (94 loc) · 2.26 KB
/
Copy pathconnecterror.ts
File metadata and controls
104 lines (94 loc) · 2.26 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
*/
import * as z from "zod/v3";
import {
collectExtraKeys as collectExtraKeys$,
safeParse,
} from "../lib/schemas.js";
import { Result as SafeParseResult } from "../types/fp.js";
import * as types from "../types/primitives.js";
import { SDKValidationError } from "./sdkvalidationerror.js";
import { VercelError } from "./vercelerror.js";
/**
* Error details.
*/
export type ErrorT = {
/**
* Stable machine-readable error code.
*/
code: string;
/**
* Human-readable error message.
*/
message: string;
additionalProperties?: { [k: string]: any } | undefined;
};
/**
* Error response returned by a Connect API operation.
*/
export type ConnectErrorData = {
/**
* Error details.
*/
error: ErrorT;
};
/**
* Error response returned by a Connect API operation.
*/
export class ConnectError extends VercelError {
/**
* Error details.
*/
error: ErrorT;
/** The original data that was passed to this error instance. */
data$: ConnectErrorData;
constructor(
err: ConnectErrorData,
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 = "ConnectError";
}
}
/** @internal */
export const ErrorT$inboundSchema: z.ZodType<ErrorT, z.ZodTypeDef, unknown> =
collectExtraKeys$(
z.object({
code: types.string(),
message: types.string(),
}).catchall(z.any()),
"additionalProperties",
true,
);
export function errorFromJSON(
jsonString: string,
): SafeParseResult<ErrorT, SDKValidationError> {
return safeParse(
jsonString,
(x) => ErrorT$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'ErrorT' from JSON`,
);
}
/** @internal */
export const ConnectError$inboundSchema: z.ZodType<
ConnectError,
z.ZodTypeDef,
unknown
> = z.object({
error: z.lazy(() => ErrorT$inboundSchema),
request$: z.instanceof(Request),
response$: z.instanceof(Response),
body$: z.string(),
})
.transform((v) => {
return new ConnectError(v, {
request: v.request$,
response: v.response$,
body: v.body$,
});
});