Effect CommunityEC
Effect Community3y ago
5 replies
kristo

Runtime Error: TypeError with Promise3

One more question - When running my effect in Vite, I get a runtime error:

 TypeError: promise3.then is not a function
TypeError: promise3.then is not a function
    at effect.ts:1606:14
    at effect4.i0 (core.ts:439:23)
    at FiberRuntime.initiateAsync (fiberRuntime.ts:963:7)
    at FiberRuntime.Async (fiberRuntime.ts:1221:10)
    at fiberRuntime.ts:1277:46
    at Const.onRun (supervisor.ts:227:12)
    at FiberRuntime.runLoop (fiberRuntime.ts:1275:32)
    at FiberRuntime.evaluateEffect (fiberRuntime.ts:845:29)
    at FiberRuntime.evaluateMessageWhileSuspended (fiberRuntime.ts:812:14)
    at FiberRuntime.drainQueueOnCurrentThread (fiberRuntime.ts:568:18)


This is the effect and code to run it:

export const fetchBook = async (...args: Parameters<typeof fetchBookEffect>) =>
  Effect.runPromise(fetchBookEffect(...args));

export const fetchBookEffect = (
  input: RequestInfo,
  catalogUrl: string,
  oauthEndpoint: string,
  init?: RequestInit
) =>
  pipe(
    Effect.succeed(new Request(input, init)),
    Effect.flatMap(req => {
      return Effect.map(getCredentials(oauthEndpoint), creds => {
        req.headers.set("Authorization", creds.token);
        return req;
      });
    }),
    Effect.tryMapPromise({
      try: req => fetch(req),
      catch: e => new FetchError(`Failed to fetch url: ${getUrl(input)}`, e)
    }),
    Effect.filterOrElse(response => response.ok, HttpError.make),
    Effect.tryMapPromise({
      try: res => res.text(),
      catch: e => new ParseError("Could not parse response.text", e)
    }),
    Effect.tryMapPromise({
      try: parser.parse,
      catch: e =>
        new ParseError(
          "Could not parse OPDS to JSON",
          e instanceof Error ? e : new Error(`OPDSParser Error ${e}`)
        )
    })
  );
Was this page helpful?