*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");
|
.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,16 +151,23 @@ 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;
|
||||||
|
|
||||||
|
if (method instanceof Error) {
|
||||||
|
error = method;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!error) {
|
||||||
|
method = method as RPCMethod;
|
||||||
try {
|
try {
|
||||||
ret = (await method.handler(request.data)) as RPCResponse | any;
|
ret = (await method.handler(request.data)) as RPCResponse | any;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error = e;
|
error = e;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
throw error;
|
throw 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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue