Domain.Rejection reference
Rejection
Section titled “Rejection”Source:
packages/domain/src/Rejection.ts
A typed reason a command or read was refused. Nothing is recorded when a command is rejected, and the caller receives the rejection exactly as declared, through an Api too.
It is Schema.TaggedError with its own type filled in, and takes the same
annotations. Any other tagged error class works in rejects as well.
Rejection: Declaring rejections
Section titled “Rejection: Declaring rejections”import * as Domain from "@alchemy.run/domain";import * as Schema from "effect/Schema";
export class NotOpen extends Domain.Rejection("NotOpen") {}
export class InsufficientFunds extends Domain.Rejection("InsufficientFunds", { balance: Schema.Int, requested: Schema.Int,}) {}Rejection: Annotating rejections
Section titled “Rejection: Annotating rejections”The third argument is its annotations, which are the rejection Schema’s
annotations too, so it takes any annotation Schema.TaggedError does. An
HTTP API reads httpApiStatus from them, as it does for any Effect error.
export class NotOwner extends Domain.Rejection("NotOwner", {}, { httpApiStatus: 403, description: "Only the account's owner may do this.",}) {}