in fusion-plugin-rpc/src/server.js [54:102]
async request<TArgs, TResult>(method: string, args: TArgs): Promise<TResult> {
const startTime = ms();
if (!this.ctx) {
throw new Error('fusion-plugin-rpc requires `ctx`');
}
if (!this.emitter) {
throw new Error('fusion-plugin-rpc requires `emitter`');
}
const scopedEmitter = this.emitter.from(this.ctx);
if (!this.handlers) {
throw new Error('fusion-plugin-rpc requires `handlers`');
}
if (!hasHandler(this.handlers, method)) {
const e = new MissingHandlerError(method);
if (scopedEmitter) {
scopedEmitter.emit('rpc:error', {
method,
origin: 'server',
error: e,
});
}
throw e;
}
try {
const result = await this.handlers[method](args, this.ctx);
if (scopedEmitter) {
scopedEmitter.emit(statKey, {
method,
status: 'success',
origin: 'server',
timing: ms() - startTime,
});
}
return result;
} catch (e) {
if (scopedEmitter) {
scopedEmitter.emit(statKey, {
method,
error: e,
status: 'failure',
origin: 'server',
timing: ms() - startTime,
});
}
throw e;
}
}