-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathunauthorized.ts
More file actions
116 lines (104 loc) · 3.07 KB
/
unauthorized.ts
File metadata and controls
116 lines (104 loc) · 3.07 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
105
106
107
108
109
110
111
112
113
114
115
116
/*
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
*/
import * as z from "zod/v3";
import { remap as remap$ } from "../../lib/primitives.js";
import { safeParse } from "../../lib/schemas.js";
import { ClosedEnum } from "../../types/enums.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { DubError } from "./duberror.js";
import { SDKValidationError } from "./sdkvalidationerror.js";
/**
* A short code indicating the error code returned.
*/
export const UnauthorizedCode = {
Unauthorized: "unauthorized",
} as const;
/**
* A short code indicating the error code returned.
*/
export type UnauthorizedCode = ClosedEnum<typeof UnauthorizedCode>;
export type UnauthorizedError = {
/**
* A short code indicating the error code returned.
*/
code: UnauthorizedCode;
/**
* A human readable explanation of what went wrong.
*/
message: string;
/**
* A link to our documentation with more details about this error code
*/
docUrl?: string | undefined;
};
/**
* Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response.
*/
export type UnauthorizedData = {
error: UnauthorizedError;
};
/**
* Although the HTTP standard specifies "unauthorized", semantically this response means "unauthenticated". That is, the client must authenticate itself to get the requested response.
*/
export class Unauthorized extends DubError {
error: UnauthorizedError;
/** 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.error?.message
|| `API error occurred: ${JSON.stringify(err)}`;
super(message, httpMeta);
this.data$ = err;
this.error = err.error;
this.name = "Unauthorized";
}
}
/** @internal */
export const UnauthorizedCode$inboundSchema: z.ZodNativeEnum<
typeof UnauthorizedCode
> = z.nativeEnum(UnauthorizedCode);
/** @internal */
export const UnauthorizedError$inboundSchema: z.ZodType<
UnauthorizedError,
z.ZodTypeDef,
unknown
> = z.object({
code: UnauthorizedCode$inboundSchema,
message: z.string(),
doc_url: z.string().optional(),
}).transform((v) => {
return remap$(v, {
"doc_url": "docUrl",
});
});
export function unauthorizedErrorFromJSON(
jsonString: string,
): SafeParseResult<UnauthorizedError, SDKValidationError> {
return safeParse(
jsonString,
(x) => UnauthorizedError$inboundSchema.parse(JSON.parse(x)),
`Failed to parse 'UnauthorizedError' from JSON`,
);
}
/** @internal */
export const Unauthorized$inboundSchema: z.ZodType<
Unauthorized,
z.ZodTypeDef,
unknown
> = z.object({
error: z.lazy(() => UnauthorizedError$inboundSchema),
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$,
});
});