-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathunauthorized.ts
More file actions
89 lines (78 loc) · 1.99 KB
/
unauthorized.ts
File metadata and controls
89 lines (78 loc) · 1.99 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
/*
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
*/
import * as z from "zod/v3";
import { ClosedEnum } from "../types/enums.js";
import * as types from "../types/primitives.js";
import { VercelError } from "./vercelerror.js";
export const Code = {
Unauthorized: "unauthorized",
} as const;
export type Code = ClosedEnum<typeof Code>;
export type UnauthorizedData = {
status: number;
code: Code;
message: string;
};
export class Unauthorized extends VercelError {
status: number;
code: Code;
/** The original data that was passed to this error instance. */
data$: UnauthorizedData;
constructor(
err: UnauthorizedData,
httpMeta: { response: Response; request: Request; body: string },
) {
const message = err.message || `API error occurred: ${JSON.stringify(err)}`;
super(message, httpMeta);
this.data$ = err;
this.status = err.status;
this.code = err.code;
this.name = "Unauthorized";
}
}
/** @internal */
export const Code$inboundSchema: z.ZodNativeEnum<typeof Code> = z.nativeEnum(
Code,
);
/** @internal */
export const Code$outboundSchema: z.ZodNativeEnum<typeof Code> =
Code$inboundSchema;
/** @internal */
export const Unauthorized$inboundSchema: z.ZodType<
Unauthorized,
z.ZodTypeDef,
unknown
> = z.object({
status: types.number(),
code: Code$inboundSchema,
message: types.string(),
request$: z.instanceof(Request),
response$: z.instanceof(Response),
body$: z.string(),
})
.transform((v) => {
return new Unauthorized(v, {
request: v.request$,
response: v.response$,
body: v.body$,
});
});
/** @internal */
export type Unauthorized$Outbound = {
status: number;
code: string;
message: string;
};
/** @internal */
export const Unauthorized$outboundSchema: z.ZodType<
Unauthorized$Outbound,
z.ZodTypeDef,
Unauthorized
> = z.instanceof(Unauthorized)
.transform(v => v.data$)
.pipe(z.object({
status: z.number(),
code: Code$outboundSchema,
message: z.string(),
}));