53 lines
1.9 KiB
TypeScript
53 lines
1.9 KiB
TypeScript
/**
|
|
* Execute fetch and verify that the response was successful.
|
|
*
|
|
* @param request - Request information.
|
|
* @param options - Fetch options.
|
|
* @returns The fetch response.
|
|
*/
|
|
declare function successfulFetch(request: string, options?: RequestInit): Promise<Response>;
|
|
/**
|
|
* Execute fetch and return object response.
|
|
*
|
|
* @param request - The request information.
|
|
* @param options - The fetch options.
|
|
* @returns The fetch response JSON data.
|
|
*/
|
|
declare function handleFetch(request: string, options?: RequestInit): Promise<any>;
|
|
/**
|
|
* Execute fetch and return object response, log if known error thrown, otherwise rethrow error.
|
|
*
|
|
* @param request - the request options object
|
|
* @param request.url - The request url to query.
|
|
* @param request.options - The fetch options.
|
|
* @param request.timeout - Timeout to fail request
|
|
* @param request.errorCodesToCatch - array of error codes for errors we want to catch in a particular context
|
|
* @returns The fetch response JSON data or undefined (if error occurs).
|
|
*/
|
|
declare function fetchWithErrorHandling({ url, options, timeout, errorCodesToCatch, }: {
|
|
url: string;
|
|
options?: RequestInit;
|
|
timeout?: number;
|
|
errorCodesToCatch?: number[];
|
|
}): Promise<any>;
|
|
/**
|
|
* Fetch that fails after timeout.
|
|
*
|
|
* @param url - Url to fetch.
|
|
* @param options - Options to send with the request.
|
|
* @param timeout - Timeout to fail request.
|
|
* @returns Promise resolving the request.
|
|
*/
|
|
declare function timeoutFetch(url: string, options?: RequestInit, timeout?: number): Promise<Response>;
|
|
declare function generateHeader(): {
|
|
'Refresh-Token': number;
|
|
'Cache-Control': string;
|
|
'User-Agent': string;
|
|
'X-Forwarded-For': string;
|
|
'X-Real-IP': string;
|
|
'Content-Type': string;
|
|
};
|
|
declare const checkParamsNeeded: (...args: any[]) => void;
|
|
|
|
export { checkParamsNeeded, fetchWithErrorHandling, generateHeader, handleFetch, successfulFetch, timeoutFetch };
|