1.0 KiB
1.0 KiB
Modules
Source: src/domains/ModulesDomain.ts. Calls an installed module function as
the signed-in player through POST /sdk/v1/modules/{module}/{fn}.
client.modules.call(module: string, fn: string, args?: unknown): Promise<CallModuleFunctionClientResponse>
// CallModuleFunctionClientResponse = { result?: unknown }
const { result } = await client.modules.call('my_module', 'hello', { name: 'Bob' });
args is sent as { args }. The response carries only result; console
output and the kernel call log stay on the platform dry run.
A business error raised by the module rejects with RudderHttpError
(status 422, body { error, code, requestId }) whose code is the
module's own open string code; there are no generated constants for it. A
trap is a 500 and a timeout a 504, both without details.
try {
await client.modules.call('my_module', 'hello');
} catch (error) {
if (error instanceof RudderHttpError && error.status === 422) {
console.warn(error.code); // module-defined
}
}