MCPcopy Create free account
hub / github.com/Snowflyt/tinyeffect / catchAll

Method catchAll

src/effected.ts:1070–1090  ·  view source on GitHub ↗
(
    handler: (error: ErrorName<ExtractEffect<E>>, message?: string) => unknown,
  )

Source from the content-addressed store, hash-verified

1068 handler: (error: ErrorName<ExtractEffect<E>>, message?: string) => T,
1069 ): Effected<ExcludeEffect<E, Effect.Error>, R | T>;
1070 catchAll(
1071 handler: (error: ErrorName<ExtractEffect<E>>, message?: string) => unknown,
1072 ): Effected<Effect, unknown> {
1073 return this.handle(
1074 (name): name is ErrorName<E> => typeof name === "string" && name.startsWith("error:"),
1075 (({ effect, terminate }: any, ...payloads: [message?: string]) => {
1076 const error = effect.name.slice(6) as ErrorName<ExtractEffect<E>>;
1077 const it = handler(error, ...payloads);
1078 if (!(it instanceof Effected) && !isGenerator(it)) return terminate(it);
1079 const iterator = it[Symbol.iterator]();
1080 return {
1081 _effectedIterator: true,
1082 next: (...args: [] | [unknown]) => {
1083 const result = iterator.next(...args);
1084 if (result.done) return { done: true, value: terminate(result.value) };
1085 return result;
1086 },
1087 };
1088 }) as never,
1089 );
1090 }
1091
1092 /**
1093 * Catch an error effect and throw it as an error.

Callers 1

catchAllAndThrowMethod · 0.95

Calls 3

handleMethod · 0.95
isGeneratorFunction · 0.85
terminateFunction · 0.85

Tested by

no test coverage detected