import { VroomError } from '../errors/vroom.error';
/**
* API error response from Vroom backend
*/
export interface ApiErrorResponse {
code: string;
message: string;
}
/**
* Error context passed to custom error handlers
*/
export interface ErrorContext {
response: Response;
code: string;
message: string;
}
/**
* Custom error handler for endpoint-specific errors.
* Return a VroomError to throw it, or null to fallback to common error handling.
*/
export type CustomErrorHandler = (ctx: ErrorContext) => VroomError | null;
/**
* Base request options shared by request and requestVoid
*/
export interface BaseRequestOptions
{
/** HTTP method */
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
/** Full URL to request */
url: string;
/** Request body (will be JSON stringified) */
body?: TBody;
/** Additional headers to include in the request */
headers?: Record;
/** Custom error handler for endpoint-specific errors */
customErrorHandler?: CustomErrorHandler;
}
/**
* Request options for endpoints that return JSON data
*/
export interface RequestOptions extends BaseRequestOptions {
/** Error message for NetworkError when fetch fails */
errorMessage: string;
}
/**
* Request options for endpoints that return no content (204, etc.)
*/
export interface RequestVoidOptions extends BaseRequestOptions {
/** Error message for NetworkError when fetch fails (optional for void requests) */
errorMessage?: string;
}
/**
* Handle API error response with optional custom handler.
*
* Flow:
* 1. Try custom handler first (for endpoint-specific errors)
* 2. Handle common errors (BadRequest, PermissionDenied)
* 3. HTTP status fallback (403, 5xx)
* 4. Default to NetworkError
*
* @param response - Fetch response object
* @param customHandler - Optional custom error handler
*/
export declare function handleApiError(response: Response, customHandler?: CustomErrorHandler): Promise;
/**
* Make an HTTP request to the Vroom API that returns JSON data.
*
* Use this for endpoints that return a response body.
* For endpoints that return no content (204), use `requestVoid` instead.
*
* @param options - Request options
* @returns Parsed JSON response
* @throws NetworkError if response body is empty (unexpected)
* @throws VroomError subclass based on error type
*/
export declare function request(options: RequestOptions): Promise;
/**
* Make an HTTP request to the Vroom API that returns no content.
*
* Use this for endpoints that return 204 No Content or empty body.
* For endpoints that return JSON data, use `request` instead.
*
* @param options - Request options
* @throws VroomError subclass based on error type
*/
export declare function requestVoid(options: RequestVoidOptions): Promise;
//# sourceMappingURL=http.d.ts.map