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

Method catchAndThrow

src/effected.ts:1101–1112  ·  view source on GitHub ↗

* Catch an error effect and throw it as an error. * @param name The name of the error effect. * @param message The message of the error. If it is a function, it will be called with the * message of the error effect, and the return value will be used as the message of the error. * @return

(
    name: Name,
    message?: string | ((message?: string) => string | undefined),
  )

Source from the content-addressed store, hash-verified

1099 * @since 0.1.1
1100 */
1101 catchAndThrow<Name extends ErrorName<ExtractEffect<E>>>(
1102 name: Name,
1103 message?: string | ((message?: string) => string | undefined),
1104 ): Effected<ExcludeEffect<E, Effect.Error<Name>>, R> {
1105 return this.catch(name, (...args) => {
1106 throw new (buildErrorClass(name))(
1107 ...(typeof message === "string" ? [message]
1108 : typeof message === "function" ? [message(...args)].filter((v) => v !== undefined)
1109 : args),
1110 );
1111 });
1112 }
1113
1114 /**
1115 * Catch all error effects and throw them as an error.

Callers

nothing calls this directly

Calls 2

catchMethod · 0.95
buildErrorClassFunction · 0.85

Tested by

no test coverage detected