chia-agent 16.1.2 → 16.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/package.json +1 -1
- package/rpc/index.d.ts +4 -0
- package/rpc/index.js +16 -3
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/rpc/index.d.ts
CHANGED
|
@@ -2,6 +2,10 @@ import { Agent as HttpsAgent } from "https";
|
|
|
2
2
|
import { Agent as HttpAgent } from "http";
|
|
3
3
|
import { TConfig } from "../config/index";
|
|
4
4
|
import { APIAgent } from "../agent/index";
|
|
5
|
+
export declare class RpcError extends Error {
|
|
6
|
+
response: unknown;
|
|
7
|
+
constructor(message: string, response: unknown);
|
|
8
|
+
}
|
|
5
9
|
type TDestination = "farmer" | "harvester" | "full_node" | "wallet" | "data_layer" | "daemon" | "pool";
|
|
6
10
|
export declare function getConnectionInfoFromConfig(destination: TDestination, config: TConfig): {
|
|
7
11
|
hostname: string;
|
package/rpc/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RPCAgent = void 0;
|
|
3
|
+
exports.RPCAgent = exports.RpcError = void 0;
|
|
4
4
|
exports.getConnectionInfoFromConfig = getConnectionInfoFromConfig;
|
|
5
5
|
exports.getConf = getConf;
|
|
6
6
|
exports.loadCertFilesFromConfig = loadCertFilesFromConfig;
|
|
@@ -14,6 +14,14 @@ const JSONbig = JSONbigBuilder({
|
|
|
14
14
|
useNativeBigInt: true,
|
|
15
15
|
alwaysParseAsBig: false,
|
|
16
16
|
});
|
|
17
|
+
class RpcError extends Error {
|
|
18
|
+
constructor(message, response) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.name = "RpcError";
|
|
21
|
+
this.response = response;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.RpcError = RpcError;
|
|
17
25
|
function getConnectionInfoFromConfig(destination, config) {
|
|
18
26
|
let hostname = "localhost";
|
|
19
27
|
let port = -1;
|
|
@@ -313,8 +321,13 @@ class RPCAgent {
|
|
|
313
321
|
return reject(new Error(`Response has no 'success' property: ${serializedData}`));
|
|
314
322
|
}
|
|
315
323
|
if (!d.success) {
|
|
316
|
-
|
|
317
|
-
|
|
324
|
+
const errorMessage = typeof d.error === "string"
|
|
325
|
+
? d.error
|
|
326
|
+
: typeof d.error_message === "string"
|
|
327
|
+
? d.error_message
|
|
328
|
+
: `RPC request failed: ${(0, logger_1.stringify)(d)}`;
|
|
329
|
+
(0, logger_1.getLogger)().info(`API failure: ${errorMessage}`);
|
|
330
|
+
return reject(new RpcError(errorMessage, d));
|
|
318
331
|
}
|
|
319
332
|
(0, logger_1.getLogger)().debug(() => `RPC response received from ${this._protocol}//${this._host}:${this._port}${options.path}`);
|
|
320
333
|
(0, logger_1.getLogger)().trace(() => `RPC response data: ${(0, logger_1.stringify)(d)}`);
|