# Struct envelope::ErrorBody

> An error object: `code`, `message`, and the code's extra fields placed next to `code`. Build it with the constructors (one per `ErrorCode`, see `errors.rs`); they use fixed message

`zaun_community_protocol::envelope::ErrorBody` · Struct

```rust
pub struct ErrorBody { … }
```

An error object: `code`, `message`, and the code's extra fields placed next to `code`. Build it with the constructors (one per `ErrorCode`, see `errors.rs`); they
use fixed messages so no secret, connection detail, member key or other member's data can
reach the wire. The extras are boxed to keep `Result<_, ErrorBody>` small.

## Fields

### `code: ErrorCode`

What went wrong; clients branch on this only.

### `message: String`

Human-readable English text; informative, never branched on.

### `extras: Box<ErrorExtras>`

The code's extra fields, serialised next to `code` (absent ones are omitted).

## Methods

### `bad_request`

```rust
pub fn bad_request(field: Option<&str>) -> Self
```

`BAD_REQUEST`, naming the offending field path when known (`"body.content"`). The
path names a schema field; never put a received value in it.

### `payload_too_large`

```rust
pub fn payload_too_large(limit: u64) -> Self
```

`PAYLOAD_TOO_LARGE` with the limit exceeded, in bytes or items.

### `unsupported_version`

```rust
pub fn unsupported_version(supported: VersionRange) -> Self
```

`UNSUPPORTED_VERSION` with the host's supported range.

### `unsupported_feature`

```rust
pub fn unsupported_feature<impl Into<Cow<'static, str>>>(feature: impl Into<Cow<'static, str>>) -> Self
```

`UNSUPPORTED_FEATURE` naming the feature (`"attachments"`, `"voice"`, a reserved
command name). The name may be dynamic (`BodyError::UnsupportedFeature`) but must be a
protocol name, never text taken from a secret or another member.

### `forbidden`

```rust
pub fn forbidden(missing: Option<u64>, reason: Option<Reason>) -> Self
```

`FORBIDDEN`, with the missing permission bits and the cause when known.

### `suspended`

```rust
pub fn suspended(until: Option<u64>) -> Self
```

`SUSPENDED`, with the end of the suspension when it has one.

### `conflict`

```rust
pub fn conflict(reason: Reason) -> Self
```

`CONFLICT` with its reason.

### `invalid_signature`

```rust
pub fn invalid_signature(object: &'static str) -> Self
```

`INVALID_SIGNATURE` naming the signed object (`"descriptor"`, `"delegation"`, …).

### `slowmode_active`

```rust
pub fn slowmode_active(retry_after_ms: u64) -> Self
```

`SLOWMODE_ACTIVE` (message as in the the protocol example).

### `rate_limited`

```rust
pub fn rate_limited(retry_after_ms: u64, scope: RateScope, category: Option<RateCategory>) -> Self
```

`RATE_LIMITED` with the scope and, when one applies, the category.

### `timed_out`

```rust
pub fn timed_out(until: u64) -> Self
```

`TIMED_OUT` until the given time.

### `busy`

```rust
pub fn busy(retry_after_ms: u64) -> Self
```

`BUSY`: the host's bounded queues are full.

### `resync_required_member`

```rust
pub fn resync_required_member() -> Self
```

`RESYNC_REQUIRED` for the member stream.

### `resync_required_channel`

```rust
pub fn resync_required_channel(channel_id: ChannelId) -> Self
```

`RESYNC_REQUIRED` for a channel stream.

### `new`

```rust
pub fn new(code: ErrorCode, message: &'static str) -> Self
```

A body with only `code` and `message`.

### `with_message`

```rust
pub fn with_message(self, message: &'static str) -> Self
```

Replaces the default message with another fixed one.

### `is_recorded`

```rust
pub const fn is_recorded(&self) -> bool
```

Whether a response carrying this error is stored as the idempotency record.

### `unsupported_command`

```rust
pub fn unsupported_command() -> Self
```

`UNSUPPORTED_COMMAND`: unknown `type`.

### `hello_required`

```rust
pub fn hello_required() -> Self
```

`HELLO_REQUIRED`: a command before a successful `session.hello`.

### `not_bound`

```rust
pub fn not_bound() -> Self
```

`NOT_BOUND`: a bound-only command on an unbound connection.

### `wrong_community`

```rust
pub fn wrong_community() -> Self
```

`WRONG_COMMUNITY`: `community_id` differs from the binding.

### `host_not_authorized`

```rust
pub fn host_not_authorized() -> Self
```

`HOST_NOT_AUTHORIZED`: no valid delegation for the community.

### `pending_approval`

```rust
pub fn pending_approval() -> Self
```

`PENDING_APPROVAL`: the member is pending.

### `admission_closed`

```rust
pub fn admission_closed() -> Self
```

`ADMISSION_CLOSED` (one code for every cause, so it is not an oracle).

### `not_found`

```rust
pub fn not_found() -> Self
```

`NOT_FOUND` (missing and invisible are indistinguishable).

### `invite_invalid`

```rust
pub fn invite_invalid() -> Self
```

`INVITE_INVALID` (one code for every cause, so it is not an oracle).

### `banned`

```rust
pub fn banned() -> Self
```

`BANNED`: sent once, then the session ends.

### `internal`

```rust
pub fn internal() -> Self
```

`INTERNAL`: details are logged on the host, never sent.

## Trait implementations

`Clone`, `Debug`, `Deserialize<'de>`, `Eq`, `PartialEq`, `Serialize`, `StructuralPartialEq`

[Full rustdoc page](/docs/api/rust/zaun-community-protocol/zaun_community_protocol/envelope/error_body/struct.ErrorBody.html)
