Handling API Errors and Updating the Database Asynchronously with Effect

Hi guys, Effect beginner here, I am struggling to call an API. The program is basically an API call and I am using catchTags to handle the error. I need to perform an async op to update the db if it errors but I am not sure how. Not sure what the 'Effect' way would be to achieve something like this. Any help would be greatly appreciated!

  const test = await program.pipe(
    Effect.retry({
      times: 3,
      schedule: Schedule.exponential("500 millis"),
    }),
    Effect.catchTags({
      ConvexError: (error) => {
        return Effect.promise(() =>
          Promise.all(
            args.messages.map(async (m) => {
              return await ctx.runMutation(internal.infobip.patchError, {
                messageId: m.messageId as Id<"messages">,
              });
            }),
          ),
        );
      },
      InfobipError: (error) => {
        console.log("INFOBIP ERROR");
        args.messages.forEach((m) => {
          ctx.runMutation(internal.infobip.patchError, {
            messageId: m.messageId as Id<"messages">,
          });
        });
        // run mutation to db to record error
        return Effect.fail(error);
      },
    }),
    Effect.runPromiseExit,
  );
Was this page helpful?