MCPcopy Create free account
hub / github.com/middleapi/orpc / onError

Function onError

packages/shared/src/interceptor.ts:46–62  ·  view source on GitHub ↗
(
  callback: NoInfer<(
    error: ReturnType<TOptions['next']> extends PromiseWithError<any, infer E> ? E : ThrowableError,
    options: TOptions,
    ...rest: TRest
  ) => Promisable<void>>,
)

Source from the content-addressed store, hash-verified

44 * Can be used for interceptors or middlewares
45 */
46export 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
64export type OnFinishState<TResult, TError>
65 = | [error: TError, data: undefined, isSuccess: false]

Callers 10

onErrorDeferredFunction · 0.90
action-form.tsFile · 0.90
dispatchErrorForKeyMethod · 0.50
subscribeListenerMethod · 0.50
redisOnErrorMethod · 0.50
redisListenerMethod · 0.50
subscribeListenerMethod · 0.50

Calls 2

callbackFunction · 0.85
nextMethod · 0.45

Tested by

no test coverage detected