*Allow handleRequest to be publicly called

*If getMethodByRequest returns an error, treat as a request error
This commit is contained in:
Derrick Hammer 2022-11-28 01:35:35 -05:00
parent cb2299f9e8
commit 9b15c738e9
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 14 additions and 6 deletions

View File

@ -137,7 +137,7 @@ export class RPCServer extends EventEmitter {
.toString("hex");
}
private async handleRequest(request: RPCRequest) {
public async handleRequest(request: RPCRequest) {
let lockedRequest = await this.waitOnRequestLock(request);
if (lockedRequest) {
@ -151,16 +151,23 @@ export class RPCServer extends EventEmitter {
return cachedRequest.value;
}
let method = this.getMethodByRequest(request) as RPCMethod;
let method = this.getMethodByRequest(request);
let ret;
let error;
if (method instanceof Error) {
error = method;
}
if (!error) {
method = method as RPCMethod;
try {
ret = (await method.handler(request.data)) as RPCResponse | any;
} catch (e) {
error = e;
}
}
if (error) {
throw error;
@ -182,6 +189,7 @@ export class RPCServer extends EventEmitter {
};
}
method = method as RPCMethod;
if (method.cacheable) {
this.cache.addItem(request, rpcResult);
}