import { LensSDKException } from "./common.exceptions"; import { AxiosResponse } from "axios"; export type PlatformErrorResponse = AxiosResponse & { body: any; }; /** * Mapping of HTTP error codes onto expected exceptions * @example * ``` * const map: HTTPErrCodeExceptionMap = { * 404: () => new SpaceNotFoundException("my-test-space"), * 405: () => new LensPlatformException(405, "Method 'PUT' not allowed") * }; * ``` */ export type HTTPErrCodeExceptionMap = Partial T>>; /** * Executes a given function, catching all exceptions. When an exception is caught * it is converted to strongly-typed `LensPlatformExtension` and thrown again. * @param fn - a function * @param exceptionsMap - map of HTTP error codes onto expected exception creators * @returns the ressult of `fn` * @throws extected exceptions or `LensPlatformException` with code 400 if it caught something unexpected * @example * ``` * const json = throwExpected( * () => fetch.get(url), * { * 404: e => e.url.includes("/user") ? * new NotFoundException(`User ${username} not found`) : * new NotFoundException(`Something else not found`), * 500: () => new TokenNotFoundException() * } * ); * ``` */ export declare const throwExpected: (fn: () => Promise, exceptionsMap?: HTTPErrCodeExceptionMap) => Promise;