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