UNPKG

3.68 kBTypeScriptView Raw
1import { SupportedResponse } from "./fetch-types";
2/**
3 * Error codes returned in responses from the API.
4 */
5export 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 * Error codes generated for client errors.
20 */
21export declare enum ClientErrorCode {
22 RequestTimeout = "notionhq_client_request_timeout",
23 ResponseError = "notionhq_client_response_error"
24}
25/**
26 * Error codes on errors thrown by the `Client`.
27 */
28export declare type NotionErrorCode = APIErrorCode | ClientErrorCode;
29/**
30 * Base error type.
31 */
32declare abstract class NotionClientErrorBase<Code extends NotionErrorCode> extends Error {
33 abstract code: Code;
34}
35/**
36 * Error type that encompasses all the kinds of errors that the Notion client will throw.
37 */
38export declare type NotionClientError = RequestTimeoutError | UnknownHTTPResponseError | APIResponseError;
39/**
40 * @param error any value, usually a caught error.
41 * @returns `true` if error is a `NotionClientError`.
42 */
43export declare function isNotionClientError(error: unknown): error is NotionClientError;
44/**
45 * Error thrown by the client if a request times out.
46 */
47export 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}
54declare type HTTPResponseErrorCode = ClientErrorCode.ResponseError | APIErrorCode;
55declare 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}
69export 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 */
74export 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 */
88export declare class APIResponseError extends HTTPResponseError<APIErrorCode> {
89 readonly name = "APIResponseError";
90 static isAPIResponseError(error: unknown): error is APIResponseError;
91}
92export declare function buildRequestError(response: SupportedResponse, bodyText: string): APIResponseError | UnknownHTTPResponseError;
93export {};
94//# sourceMappingURL=errors.d.ts.map
\No newline at end of file