-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathhttpvalidationerror.ts
More file actions
76 lines (67 loc) · 1.98 KB
/
httpvalidationerror.ts
File metadata and controls
76 lines (67 loc) · 1.98 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
/*
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
*/
import * as z from "zod/v4-mini";
import {
ValidationError,
ValidationError$inboundSchema,
ValidationError$Outbound,
ValidationError$outboundSchema,
} from "../components/validationerror.js";
import { PolarError } from "./polarerror.js";
export type HTTPValidationErrorData = {
detail?: Array<ValidationError> | undefined;
};
export class HTTPValidationError extends PolarError {
detail?: Array<ValidationError> | undefined;
/** The original data that was passed to this error instance. */
data$: HTTPValidationErrorData;
constructor(
err: HTTPValidationErrorData,
httpMeta: { response: Response; request: Request; body: string },
) {
const message = "message" in err && typeof err.message === "string"
? err.message
: `API error occurred: ${JSON.stringify(err)}`;
super(message, httpMeta);
this.data$ = err;
if (err.detail != null) this.detail = err.detail;
this.name = "HTTPValidationError";
}
}
/** @internal */
export const HTTPValidationError$inboundSchema: z.ZodMiniType<
HTTPValidationError,
unknown
> = z.pipe(
z.object({
detail: z.optional(z.array(ValidationError$inboundSchema)),
request$: z.custom<Request>(x => x instanceof Request),
response$: z.custom<Response>(x => x instanceof Response),
body$: z.string(),
}),
z.transform((v) => {
return new HTTPValidationError(v, {
request: v.request$,
response: v.response$,
body: v.body$,
});
}),
);
/** @internal */
export type HTTPValidationError$Outbound = {
detail?: Array<ValidationError$Outbound> | undefined;
};
/** @internal */
export const HTTPValidationError$outboundSchema: z.ZodMiniType<
HTTPValidationError$Outbound,
HTTPValidationError
> = z.pipe(
z.pipe(
z.custom<HTTPValidationError>(x => x instanceof HTTPValidationError),
z.transform(v => v.data$),
),
z.object({
detail: z.optional(z.array(ValidationError$outboundSchema)),
}),
);