*If an error, return it as a RPCResponse object instead of throwing an error

This commit is contained in:
Derrick Hammer 2022-08-30 22:17:39 -04:00
parent 7916f6e4d6
commit f4cb988053
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 4 additions and 4 deletions

View File

@ -1,5 +1,5 @@
import { ErrTuple } from "libskynet";
import type { RPCRequest } from "@lumeweb/relay-types";
import type { RPCRequest, RPCResponse } from "@lumeweb/relay-types";
import {
RpcQueryOptions,
StreamHandlerFunction,
@ -169,10 +169,10 @@ export abstract class RpcQueryBase {
return this;
}
get result(): Promise<any> {
return (this._promise as Promise<any>).then((result) => {
get result(): Promise<RPCResponse> {
return (this._promise as Promise<any>).then((result): RPCResponse => {
if (result[1]) {
throw new Error(result[1]);
return { error: result[1] };
}
return result[0];
});