Skip to main content

Function: withIpcHandler()

function withIpcHandler<T>(
channelName: string,
handler: () => Promisable<T>,
options?: WithIpcHandlerOptions<T>
): Promise<IpcResponse<T>>;

Defined in: electron/services/ipc/utils.ts:339

Wraps an IPC handler with standardized error handling, logging, and response formatting.

Type Parameters​

T​

T

Parameters​

channelName​

string

Name of the IPC channel

handler​

() => Promisable<T>

The handler function to wrap

options?​

WithIpcHandlerOptions<T>

Returns​

Promise<IpcResponse<T>>

The wrapped handler result

Remarks​

Provides consistent error handling, logging, and response formatting for all IPC handlers. Automatically logs handler execution and errors, validates parameters if provided, and ensures all responses follow the standardized format.

Example​

import { SITES_CHANNELS } from "@shared/types/preload";

const result = await withIpcHandler(
SITES_CHANNELS.getSites,
async () => this.uptimeOrchestrator.getSites(),
{
validateResult: (value) =>
Array.isArray(value) ? null : ["Expected an array"],
}
);