Kind: Interface
Source: packages/microservices/interfaces/packet.interface.ts
Part of: Microservices
WritePacket<T> represents the result of writing or handling a microservice packet response. It carries either a successful typed response or an err, along with lifecycle and status information used to determine whether the underlying request has completed or been disposed.
Properties
| Property | Type |
|---|---|
err | any |
response | T |
isDisposed | boolean |
status | string |
Diagram
mermaidgraph LR Request[Microservice Request] --> Handler[Packet Handler] Handler --> Packet[WritePacket<T>] Packet --> Response[response: T] Packet --> Error[err: any] Packet --> Status[status: string] Packet --> Disposed[isDisposed: boolean]
Usage
tsimport type { WritePacket } from './interfaces/packet.interface';
interface UserProfile {
id: string;
name: string;
}
const packet: WritePacket<UserProfile> = {
err: null,
response: {
id: 'user_123',
name: 'Ada Lovelace',
},
isDisposed: false,
status: 'success',
};
if (packet.err) {
console.error('Microservice request failed:', packet.err);
} else if (!packet.isDisposed) {
console.log(`Received ${packet.status} response:`, packet.response);
}
AI Coding Instructions
- Use
WritePacket<T>with a concrete response type so consumers can safely accessresponse. - Check
errbefore processingresponse, since error packets may not contain meaningful response data. - Respect
isDisposedwhen handling asynchronous responses; avoid writing to or consuming packets after disposal. - Keep
statusvalues consistent with the surrounding microservice transport or packet-handling conventions. - Preserve packet metadata when forwarding or transforming responses between microservice layers.
Was this page helpful?