Improving TypeScript Function to Retrieve and Parse Reviews Count

is there better way to do mapping errors like this ?
export const getReviewsCount = (page: Page) => {
  return Effect.tryPromise({
    catch: (err: any) => new GetReviewsCountError({ msg: err.message }),
    try: () =>
      page.$(
        "::-p-xpath(//section[@id='reviews']//div[contains(text(),'reviews')][not(@aria-hidden)])"
      ),
  }).pipe(
    Effect.andThen(Option.fromNullable),
    Effect.andThen((el) => el.evaluate((el) => el.textContent!)),
    Effect.andThen(String.replace(" reviews", "")),
    Effect.andThen(String.replaceAll(",", "")),
    Effect.andThen(String.trim),
    Effect.andThen(Number.parseInt),
    Effect.catchTags({
      NoSuchElementException: (err) =>
        new GetReviewsCountError({ msg: err.message }),
      UnknownException: (err) => new GetReviewsCountError({ msg: err.message }),
    })
  );
};
Was this page helpful?