[**Documentation**](../../../README)

***

[Documentation](../../../README) / [@zerotal/monitor](../README) / MonitorPayloadMiddleware

# Class: MonitorPayloadMiddleware

Defined in: [monitor/src/middleware/MonitorPayloadMiddleware.ts:50](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/monitor/src/middleware/MonitorPayloadMiddleware.ts#L50)

A single step in a middleware pipeline.

## Contract
A pipe does exactly one of three things:
- **Continue:** `return next()` to run the rest of the chain.
- **Short-circuit:** produce a `Response` and stop. Either `return` it
  directly, or set `ctx.response` and `return` (void). Do NOT call `next()`.
- **Wrap:** `const res = await next()`, inspect/transform `res`, then return
  the (possibly new) `Response` — or just mutate `ctx.response` and return void.

`ctx.response` is the canonical store: returning a `Response` is sugar the
pipeline mirrors onto it, and a `void` return leaves it untouched (so it can
never erase a response a deeper pipe already set).

## Example

```ts
class RequireAuth implements Pipe<HttpContext> {
  async handle(ctx: HttpContext, next: NextFn): Promise<Response | void> {
    if (!ctx.user) {
      return Response.json({ message: 'Unauthenticated.' }, { status: 401 });
    }
    return next();
  }
}
```

## Implements

- [`Pipe`](../../core/index/interfaces/Pipe)\<[`HttpContext`](../../core/index/classes/HttpContext)\>

## Constructors

### Constructor

> **new MonitorPayloadMiddleware**(): `MonitorPayloadMiddleware`

#### Returns

`MonitorPayloadMiddleware`

## Methods

### handle()

> **handle**(`http`, `next`): `Promise`\<`void` \| `Response`\>

Defined in: [monitor/src/middleware/MonitorPayloadMiddleware.ts:51](https://github.com/zerotaldev/zerotal/blob/1d6fb26b05b18ba077de1bfaeb46c42131cd8b70/packages/monitor/src/middleware/MonitorPayloadMiddleware.ts#L51)

#### Parameters

##### http

[`HttpContext`](../../core/index/classes/HttpContext)

##### next

[`NextFn`](../../core/index/type-aliases/NextFn)

#### Returns

`Promise`\<`void` \| `Response`\>

#### Implementation of

[`Pipe`](../../core/index/interfaces/Pipe).[`handle`](../../core/index/interfaces/Pipe#handle)
