# IMQWrapCall interface · @imqueue/rpc

Source: https://imqueue.org/api/rpc/latest/rpc.imqwrapcall/
Published: 2026-08-04
Author: @imqueue maintainers (https://github.com/imqueue)
Package: @imqueue/rpc 3.5.3 — generated reference, not hand-written

Around hook wrapping the actual service method invocation. It receives the request/response and a `next` callback that runs the method and resolves to its return value; it MUST call `next()` (returning its resolved value) to produce the response data. Unlike `beforeCall`/`afterCall`, this lets a hook run the method inside its own scope — e.g. establishing an OpenTelemetry context so any spans the method (and its downstream calls) create nest under the request span. When unset, the method is invoked directly.

**Signature:**

```typescript
export interface IMQWrapCall<_T> 
```

## Remarks

Service side only — there is no client equivalent, despite the type parameter.

The hook's resolved value is the response data. Calling `next()` exactly once and returning its value is the required pattern, but it is not enforced: omitting `next()` silently skips the method and returns your value instead, and calling it twice runs the method twice.

Unlike [IMQBeforeCall](https://imqueue.org/api/rpc/latest/rpc.imqbeforecall/) and [IMQAfterCall](https://imqueue.org/api/rpc/latest/rpc.imqaftercall/), errors here are not swallowed — anything this hook throws, or that propagates out of `next()`, becomes the call's error response (`IMQ_RPC_CALL_ERROR`, preserving the thrown error's own `code` when it has one). So a wrapping hook can safely let failures through or rethrow enriched errors.

Invoked bound to the service instance; `this` is untyped, so do not use an arrow function if you need it.

