# Notice

`class` in `core` · v0.12.0

<https://seedcord.org/docs/packages/core/0.12.0/classes/notice>

Base class for a user-facing refusal or a reported fault.

Throw a `Notice` to stop a handler and reply to the user. The framework catches it at the controller
boundary and renders [`render`](/docs/packages/core/0.12.0/classes/notice#render), which always decides what the user sees. With `report`
false that render is all that happens. With `report` true the framework also logs the fault and
publishes it to the `handledException` bus. A raw, non-Notice throw shows the generic message.

```ts
abstract class Notice extends Error
```

## Examples

```ts
import { Notice, BuilderComponent, type RenderContext, type ReplyResponse } from '@seedcord/gateway';
import { TextDisplayBuilder } from '@discordjs/builders';

// reading `.component` applies the configured bot color to the container accent
class TooPoorCard extends BuilderComponent<'container'> {
    constructor(balance: number) {
        super('container');
        this.instance.addTextDisplayComponents(
            new TextDisplayBuilder().setContent(`### Insufficient balance\nYou need more than ${balance} coins.`)
        );
    }
}

class TooPoor extends Notice {
    constructor(private readonly balance: number) {
        super(`balance ${balance} is below the cost`);
    }

    override render(_ctx: RenderContext): ReplyResponse {
        return { components: [new TooPoorCard(this.balance).component] };
    }
}

// in a handler, throwing stops the handler and replies with render(ctx)
if (wallet.balance < cost) throw new TooPoor(wallet.balance);
```

## Constructors

### constructor

```ts
protected Notice(message: string, options?: ErrorOptions)
```

Constructs a new instance of the `Notice` class

## Properties

### ephemeral

```ts
public ephemeral: boolean
```

Whether the reply is ephemeral, seen only by the invoking user. Set it false for a refusal the
whole channel should see.

### report

```ts
public report: boolean
```

Whether this denial is a reported fault. True also logs it and publishes it to the `handledException`
bus. The user always sees [`render`](/docs/packages/core/0.12.0/classes/notice#render) either way.

### summary

```ts
public summary?: string
```

A short one-line reason. When every gate in an [`or`](/docs/packages/core/0.12.0/functions/or) refuses and each one sets this, `or`
throws a refusal listing them under `You need to meet at least one of these:`. Write a verb phrase that
finishes that line, for example, "be the bot owner".

## Methods

### render

```ts
public render(_ctx: RenderContext): ReplyResponse
```

Builds what the user sees. Called fresh each time the denial is shown, so the builders are new
and the bot color resolves at render time. By default it returns seedcord's refusal card with the message as
its text. Override it to show your own components.
