Spaces:
Build error
Build error
File size: 3,659 Bytes
7d9f678 |
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 |
import { SupportedResponse } from "./fetch-types";
/**
* Error codes returned in responses from the API.
*/
export declare enum APIErrorCode {
Unauthorized = "unauthorized",
RestrictedResource = "restricted_resource",
ObjectNotFound = "object_not_found",
RateLimited = "rate_limited",
InvalidJSON = "invalid_json",
InvalidRequestURL = "invalid_request_url",
InvalidRequest = "invalid_request",
ValidationError = "validation_error",
ConflictError = "conflict_error",
InternalServerError = "internal_server_error",
ServiceUnavailable = "service_unavailable"
}
/**
* Error codes generated for client errors.
*/
export declare enum ClientErrorCode {
RequestTimeout = "notionhq_client_request_timeout",
ResponseError = "notionhq_client_response_error"
}
/**
* Error codes on errors thrown by the `Client`.
*/
export type NotionErrorCode = APIErrorCode | ClientErrorCode;
/**
* Base error type.
*/
declare abstract class NotionClientErrorBase<Code extends NotionErrorCode> extends Error {
abstract code: Code;
}
/**
* Error type that encompasses all the kinds of errors that the Notion client will throw.
*/
export type NotionClientError = RequestTimeoutError | UnknownHTTPResponseError | APIResponseError;
/**
* @param error any value, usually a caught error.
* @returns `true` if error is a `NotionClientError`.
*/
export declare function isNotionClientError(error: unknown): error is NotionClientError;
/**
* Error thrown by the client if a request times out.
*/
export declare class RequestTimeoutError extends NotionClientErrorBase<ClientErrorCode.RequestTimeout> {
readonly code = ClientErrorCode.RequestTimeout;
readonly name = "RequestTimeoutError";
constructor(message?: string);
static isRequestTimeoutError(error: unknown): error is RequestTimeoutError;
static rejectAfterTimeout<T>(promise: Promise<T>, timeoutMS: number): Promise<T>;
}
type HTTPResponseErrorCode = ClientErrorCode.ResponseError | APIErrorCode;
declare class HTTPResponseError<Code extends HTTPResponseErrorCode> extends NotionClientErrorBase<Code> {
readonly name: string;
readonly code: Code;
readonly status: number;
readonly headers: SupportedResponse["headers"];
readonly body: string;
constructor(args: {
code: Code;
status: number;
message: string;
headers: SupportedResponse["headers"];
rawBodyText: string;
});
}
export declare function isHTTPResponseError(error: unknown): error is UnknownHTTPResponseError | APIResponseError;
/**
* Error thrown if an API call responds with an unknown error code, or does not respond with
* a property-formatted error.
*/
export declare class UnknownHTTPResponseError extends HTTPResponseError<ClientErrorCode.ResponseError> {
readonly name = "UnknownHTTPResponseError";
constructor(args: {
status: number;
message: string | undefined;
headers: SupportedResponse["headers"];
rawBodyText: string;
});
static isUnknownHTTPResponseError(error: unknown): error is UnknownHTTPResponseError;
}
/**
* A response from the API indicating a problem.
* Use the `code` property to handle various kinds of errors. All its possible values are in `APIErrorCode`.
*/
export declare class APIResponseError extends HTTPResponseError<APIErrorCode> {
readonly name = "APIResponseError";
static isAPIResponseError(error: unknown): error is APIResponseError;
}
export declare function buildRequestError(response: SupportedResponse, bodyText: string): APIResponseError | UnknownHTTPResponseError;
export {};
//# sourceMappingURL=errors.d.ts.map |