1 | import { SupportedResponse } from "./fetch-types";
|
2 |
|
3 |
|
4 |
|
5 | export declare enum APIErrorCode {
|
6 | Unauthorized = "unauthorized",
|
7 | RestrictedResource = "restricted_resource",
|
8 | ObjectNotFound = "object_not_found",
|
9 | RateLimited = "rate_limited",
|
10 | InvalidJSON = "invalid_json",
|
11 | InvalidRequestURL = "invalid_request_url",
|
12 | InvalidRequest = "invalid_request",
|
13 | ValidationError = "validation_error",
|
14 | ConflictError = "conflict_error",
|
15 | InternalServerError = "internal_server_error",
|
16 | ServiceUnavailable = "service_unavailable"
|
17 | }
|
18 |
|
19 |
|
20 |
|
21 | export declare enum ClientErrorCode {
|
22 | RequestTimeout = "notionhq_client_request_timeout",
|
23 | ResponseError = "notionhq_client_response_error"
|
24 | }
|
25 |
|
26 |
|
27 |
|
28 | export declare type NotionErrorCode = APIErrorCode | ClientErrorCode;
|
29 |
|
30 |
|
31 |
|
32 | declare abstract class NotionClientErrorBase<Code extends NotionErrorCode> extends Error {
|
33 | abstract code: Code;
|
34 | }
|
35 |
|
36 |
|
37 |
|
38 | export declare type NotionClientError = RequestTimeoutError | UnknownHTTPResponseError | APIResponseError;
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | export declare function isNotionClientError(error: unknown): error is NotionClientError;
|
44 |
|
45 |
|
46 |
|
47 | export declare class RequestTimeoutError extends NotionClientErrorBase<ClientErrorCode.RequestTimeout> {
|
48 | readonly code = ClientErrorCode.RequestTimeout;
|
49 | readonly name = "RequestTimeoutError";
|
50 | constructor(message?: string);
|
51 | static isRequestTimeoutError(error: unknown): error is RequestTimeoutError;
|
52 | static rejectAfterTimeout<T>(promise: Promise<T>, timeoutMS: number): Promise<T>;
|
53 | }
|
54 | declare type HTTPResponseErrorCode = ClientErrorCode.ResponseError | APIErrorCode;
|
55 | declare class HTTPResponseError<Code extends HTTPResponseErrorCode> extends NotionClientErrorBase<Code> {
|
56 | readonly name: string;
|
57 | readonly code: Code;
|
58 | readonly status: number;
|
59 | readonly headers: SupportedResponse["headers"];
|
60 | readonly body: string;
|
61 | constructor(args: {
|
62 | code: Code;
|
63 | status: number;
|
64 | message: string;
|
65 | headers: SupportedResponse["headers"];
|
66 | rawBodyText: string;
|
67 | });
|
68 | }
|
69 | export declare function isHTTPResponseError(error: unknown): error is UnknownHTTPResponseError | APIResponseError;
|
70 | /**
|
71 | * Error thrown if an API call responds with an unknown error code, or does not respond with
|
72 | * a property-formatted error.
|
73 | */
|
74 | export declare class UnknownHTTPResponseError extends HTTPResponseError<ClientErrorCode.ResponseError> {
|
75 | readonly name = "UnknownHTTPResponseError";
|
76 | constructor(args: {
|
77 | status: number;
|
78 | message: string | undefined;
|
79 | headers: SupportedResponse["headers"];
|
80 | rawBodyText: string;
|
81 | });
|
82 | static isUnknownHTTPResponseError(error: unknown): error is UnknownHTTPResponseError;
|
83 | }
|
84 | /**
|
85 | * A response from the API indicating a problem.
|
86 | * Use the `code` property to handle various kinds of errors. All its possible values are in `APIErrorCode`.
|
87 | */
|
88 | export declare class APIResponseError extends HTTPResponseError<APIErrorCode> {
|
89 | readonly name = "APIResponseError";
|
90 | static isAPIResponseError(error: unknown): error is APIResponseError;
|
91 | }
|
92 | export declare function buildRequestError(response: SupportedResponse, bodyText: string): APIResponseError | UnknownHTTPResponseError;
|
93 | export {};
|
94 |
|
\ | No newline at end of file |