import { HttpError, HttpResponse } from '../client/HttpResponse';
/**
* A function that takes a parameter of type `P` and returns a result of type `R`
*/
export interface PromiseFunction
{
(parameter: P): R;
}
/**
* Process a {@link HttpResponse} to throw the {@link HttpResponse.error} if it exists.
*
* Should be called in the {@link Promise.then} of a `Promise>`
* to convert it to a `Promise`.
*
* For common usage, {@link unwrapHttpPromise} should be preferred as it deals better with TS types.
* @param httpResponse The response to be processed.
*/
export declare function processHttpResponse(httpResponse: HttpResponse): T;
/**
* Convert a `Promise>` to a `Promise`.
*
* In case an HTTP error is returned by `HttpResponse`, a rejected `Promise` is issued
* with the error object {@link HttpError}
* @param httpPromise The `Promise` to be unwrapped
*/
export declare function unwrapHttpPromise(httpPromise: Promise>): Promise;
/**
* Verify is an object seems to be a {@link HttpError}.
*
* Returns `true` if the object seems to be a {@link HttpError}, else `false`.
*/
export declare function isHttpError(object: unknown): object is HttpError;
/**
* A mutable safe `Promise` that ensures:
* - Either a then function is provided or either an info log statement will be issued
* - Either a catch function is provided or either a warning log statement will be issued
* - Then and Catch functions are wrapped to ensure that if an error occurs during the execution,
* an error statement is issued
*
* It also contains a `debugContext` that is used for logging in case an error occurs.
*/
export declare class HttpPromise {
private readonly debugContext?;
private isThenAttached;
private isCaughtAttached;
protected promise: Promise;
constructor(basePromise: Promise, debugContext?: object | undefined);
/**
* Execute a function after the `Promise` has been resolved.
*
* The function can:
* - Just execute some code using the result
* - Transform the result into another object
* - Throw an error of type {@link HttpError} that will trigger the catch function
*
* If the {@link thenFunction} throws an error:
* - The error will be caught and logged
* - A {@link genericError} will be thrown
*
* The then function returns the `this` instance of {@link HttpPromise} containing and updating `Promise`.
* If {@link thenFunction} has no return statement, a `HttpPromise` will be returned,
* else a `HttpPromise` parametrized with the returned type will be returned.
*
* @param thenFunction The code that will be executed after the `Promise` has been resolved.
*/
then(thenFunction: PromiseFunction): HttpPromise>;
/**
* Execute a function after an error has happened resolving the `Promise` or executing {@link then} functions.
*
* This `catch` method should be called after all {@link then} functions has been called,
* else it might not catch errors that have arisen from the {@link then} functions execution.
*
* This `catch` method may however be called before some {@link then} functions to provide a recovery feature.
* It is the same as with a classic `Promise`, if something is returned from the {@link catchFunction},
* then the promise is considered as recovered and the next {@link then} calls will be executed.
*
* If the {@link catchFunction} throws an error:
* - The error will be caught and logged
* - A {@link genericError} will be thrown
*
* @param catchFunction The code that will do something with the {@link HttpError}
* and possibility recover the `Promise`.
*/
catch(catchFunction: PromiseFunction): HttpPromise>;
/**
* Returns the corresponding raw `Promise`.
*
* Once the {@link toPromise} method is called, verifications that {@link then} and {@link catch}
* functions are attached are not made anymore. So:
* - Either this should be called after {@link then} and {@link catch} functions are attached
* - Either then are catch functions should be attached to the returned `Promise`. Usage of {@link safeThen}
* and {@link safeCatch} is recommended for that
*/
toPromise(): Promise;
/**
* Returns the debug context if it exists.
*
* This should be used only to make copies to the {@link HttpPromise} or to display debugging information.
*/
getDebugContext(): object | undefined;
}