*Allow handleRequest to be publicly called
*If getMethodByRequest returns an error, treat as a request error
This commit is contained in:
parent
cb2299f9e8
commit
9b15c738e9
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue