Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

848 B
Raw Blame
import { Effect } from "effect";
import type { ApiFailure } from "../errors/errors.js";
import { InvalidArgument } from "../errors/errors.js";

function notYours(id: string): InvalidArgument {
  return new InvalidArgument({
    message: `Comment ${id} was not found, or someone else wrote it.`,
    hint: "You can only change your own comments. Run kaneo comment list <task> to see the ids.",
  });
}

export const asOwnComment =
  (id: string) =>
  <A, R>(
    effect: Effect.Effect<A, ApiFailure, R>,
  ): Effect.Effect<A, ApiFailure | InvalidArgument, R> =>
    effect.pipe(
      Effect.catchTags({
        NotFound: () => Effect.fail(notYours(id)),
        InvalidRequest: (error) =>
          /could not be determined|not found/iu.test(error.message)
            ? Effect.fail(notYours(id))
            : Effect.fail(error),
      }),
    );