# Enum command::BodyError

> A body that cannot be accepted. Each variant maps to one error code of the protocol; the envelope layer adds `request_id`, the message text and the extra fields.

`zaun_community_protocol::command::BodyError` · Enum

```rust
pub enum BodyError { … }
```

A body that cannot be accepted. Each variant maps to one error code of the protocol; the envelope
layer adds `request_id`, the message text and the extra fields.

SPEC: the protocol lets an over-limit field be either `BAD_REQUEST` ("value out of range") or
`PAYLOAD_TOO_LARGE` ("an envelope or field exceeds the protocol"). This crate applies one rule: a
text, byte string or list **longer** than a the protocol maximum is `BodyError::PayloadTooLarge`;
every other violation (missing, ill-typed, below a minimum, numeric range, rule) is
`BodyError::BadRequest`.

## Variants

### `BadRequest { field, detail }`

`BAD_REQUEST{field?}`: malformed, missing, ill-typed or out-of-range value.

### `UnsupportedCommand`

`UNSUPPORTED_COMMAND`: unknown `type`, or a reserved namespace.

### `UnsupportedFeature { feature }`

`UNSUPPORTED_FEATURE{feature}`: a known name or value not implemented in v1.

### `PayloadTooLarge { field, limit }`

`PAYLOAD_TOO_LARGE{limit}`: a field longer than its the protocol maximum.

## Methods

### `code`

```rust
pub const fn code(&self) -> ErrorCode
```

The the protocol error code to answer with.

### `field`

```rust
pub fn field(&self) -> Option<&str>
```

The field at fault, when one is known.

### `bad`

```rust
pub fn bad<impl Into<String>>(field: &str, detail: impl Into<String>) -> Self
```

`BAD_REQUEST` blaming `field`.

### `too_large`

```rust
pub fn too_large(field: &str, limit: usize) -> Self
```

`PAYLOAD_TOO_LARGE` for `field` with `limit`.

### `unsupported`

```rust
pub fn unsupported(feature: &str) -> Self
```

`UNSUPPORTED_FEATURE` for `feature`.

## Trait implementations

`Clone`, `Debug`, `Display`, `Eq`, `Error`, `PartialEq`, `StructuralPartialEq`

[Full rustdoc page](/docs/api/rust/zaun-community-protocol/zaun_community_protocol/command/error/enum.BodyError.html)
