(
callback: NoInfer<(
error: ReturnType<TOptions['next']> extends PromiseWithError<any, infer E> ? E : ThrowableError,
options: TOptions,
...rest: TRest
) => Promisable<void>>,
)
| 44 | * Can be used for interceptors or middlewares |
| 45 | */ |
| 46 | export function onError<T, TOptions extends { next(): any }, TRest extends any[]>( |
| 47 | callback: NoInfer<( |
| 48 | error: ReturnType<TOptions['next']> extends PromiseWithError<any, infer E> ? E : ThrowableError, |
| 49 | options: TOptions, |
| 50 | ...rest: TRest |
| 51 | ) => Promisable<void>>, |
| 52 | ): (options: TOptions, ...rest: TRest) => T | Promise<Awaited<ReturnType<TOptions['next']>>> { |
| 53 | return async (options, ...rest) => { |
| 54 | try { |
| 55 | return await options.next() |
| 56 | } |
| 57 | catch (error) { |
| 58 | await callback(error as any, options, ...rest) |
| 59 | throw error |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | export type OnFinishState<TResult, TError> |
| 65 | = | [error: TError, data: undefined, isSuccess: false] |
no test coverage detected