@datalayer/core
Version:
[](https://datalayer.io)
88 lines (87 loc) • 2.68 kB
TypeScript
/**
* Error wrapper for failed HTTP responses.
* Includes response details, warnings, errors, and tracebacks.
*/
export declare class RunResponseError extends Error {
/**
* Creates a RunResponseError from a Response object.
* Extracts error details from response JSON.
*
* @param response - The failed HTTP response
* @returns Promise resolving to RunResponseError instance
*/
static create(response: Response): Promise<RunResponseError>;
/**
* Create a new response error.
*/
constructor(response: Response, message?: string, warnings?: undefined, errors?: undefined, exceptionMessage?: undefined, traceback?: string);
/**
* Warnings listed in the response.
*/
readonly warnings: string[];
/**
* Errors listed in the response.
*/
readonly errors: string[];
/**
* The response associated with the error.
*/
readonly response: Response;
/**
* The exception associated with the error.
*/
readonly exceptionMessage?: string;
/**
* The traceback associated with the error.
*/
readonly traceback: string;
private static _defaultMessage;
}
/**
* Error wrapper for network failures.
* Thrown when HTTP request fails due to connectivity issues.
*/
export declare class NetworkError extends TypeError {
/**
* Creates a NetworkError from the original TypeError.
*
* @param original - The original network error
*/
constructor(original: TypeError);
}
/**
* Options for Datalayer API requests.
*/
export interface IRequestDatalayerAPIOptions {
/** Target URL for the request */
url: string;
/** HTTP method (GET, POST, PUT, DELETE, etc.) */
method?: string;
/** Request body (JSON object or FormData) */
body?: any;
/** Custom HTTP headers */
headers?: Record<string, string>;
/** JWT bearer token for authentication */
token?: string;
/** AbortSignal for request cancellation */
signal?: AbortSignal;
}
/**
* Makes authenticated HTTP requests to Datalayer APIs.
* Handles JSON and FormData, includes auth headers, and manages redirects.
*
* @param options - Request configuration
* @returns Promise resolving to response data
* @throws {NetworkError} On network failures
* @throws {RunResponseError} On HTTP error responses
*
* @example
* ```typescript
* const data = await requestDatalayerAPI({
* url: 'https://api.datalayer.run/users',
* method: 'GET',
* token: 'eyJhbGc...'
* });
* ```
*/
export declare function requestDatalayerAPI<T = any>({ url, method, body, token, signal, headers, }: IRequestDatalayerAPIOptions): Promise<T>;