UNPKG

2.94 kBTypeScriptView Raw
1/// <reference types="node" />
2/// <reference types="node" />
3import type { IncomingHttpHeaders } from 'node:http';
4import type { AxiosResponse } from 'axios';
5import type { WebAPICallResult } from './WebClient';
6/**
7 * All errors produced by this package adhere to this interface
8 */
9export interface CodedError extends NodeJS.ErrnoException {
10 code: ErrorCode;
11}
12/**
13 * A dictionary of codes for errors produced by this package
14 */
15export declare enum ErrorCode {
16 RequestError = "slack_webapi_request_error",
17 HTTPError = "slack_webapi_http_error",
18 PlatformError = "slack_webapi_platform_error",
19 RateLimitedError = "slack_webapi_rate_limited_error",
20 FileUploadInvalidArgumentsError = "slack_webapi_file_upload_invalid_args_error",
21 FileUploadReadFileDataError = "slack_webapi_file_upload_read_file_data_error"
22}
23export type WebAPICallError = WebAPIPlatformError | WebAPIRequestError | WebAPIHTTPError | WebAPIRateLimitedError;
24export type WebAPIFilesUploadError = WebAPIFileUploadInvalidArgumentsError;
25export interface WebAPIFileUploadInvalidArgumentsError extends CodedError {
26 code: ErrorCode.FileUploadInvalidArgumentsError;
27 data: WebAPICallResult & {
28 error: string;
29 };
30}
31export interface WebAPIPlatformError extends CodedError {
32 code: ErrorCode.PlatformError;
33 data: WebAPICallResult & {
34 error: string;
35 };
36}
37export interface WebAPIRequestError extends CodedError {
38 code: ErrorCode.RequestError;
39 original: Error;
40}
41export interface WebAPIHTTPError extends CodedError {
42 code: ErrorCode.HTTPError;
43 statusCode: number;
44 statusMessage: string;
45 headers: IncomingHttpHeaders;
46 body?: any;
47}
48export interface WebAPIRateLimitedError extends CodedError {
49 code: ErrorCode.RateLimitedError;
50 retryAfter: number;
51}
52/**
53 * Factory for producing a {@link CodedError} from a generic error
54 */
55export declare function errorWithCode(error: Error, code: ErrorCode): CodedError;
56/**
57 * A factory to create WebAPIRequestError objects
58 * @param original - original error
59 * @param attachOriginal - config indicating if 'original' property should be added on the error object
60 */
61export declare function requestErrorWithOriginal(original: Error, attachOriginal: boolean): WebAPIRequestError;
62/**
63 * A factory to create WebAPIHTTPError objects
64 * @param response - original error
65 */
66export declare function httpErrorFromResponse(response: AxiosResponse): WebAPIHTTPError;
67/**
68 * A factory to create WebAPIPlatformError objects
69 * @param result - Web API call result
70 */
71export declare function platformErrorFromResult(result: WebAPICallResult & {
72 error: string;
73}): WebAPIPlatformError;
74/**
75 * A factory to create WebAPIRateLimitedError objects
76 * @param retrySec - Number of seconds that the request can be retried in
77 */
78export declare function rateLimitedErrorWithDelay(retrySec: number): WebAPIRateLimitedError;
79//# sourceMappingURL=errors.d.ts.map
\No newline at end of file