Skip to content

Domain.Rejection reference

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.

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,
}) {}

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.",
}) {}