Skip to content

Commit d44fc43

Browse files
committed
Refactor FetchAccountId action enum and error handling
1 parent b0f4813 commit d44fc43

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

src/proto/node.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@ enum Action {
5454
FetchDepositAddresses=7;
5555
FetchTicker=8;
5656
FetchCurrency=9;
57-
FetchAccountId=10;
58-
Call=11;
57+
Call=10;
58+
FetchAccountId=11;
5959
}

src/server.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import {
2424
buildHttpClientOverrideFromMetadata,
2525
} from "./helpers";
2626

27-
2827
const packageDef = protoLoader.fromJSON(
2928
descriptor as unknown as Record<string, unknown>,
3029
);
@@ -215,14 +214,17 @@ export function getServer(
215214
}
216215
case Action.FetchAccountId: {
217216
try {
218-
let accountId: string;
219-
let uid: string;
217+
let accountId: string | undefined;
218+
let uid: string | undefined;
220219

221-
const temp_broker = (broker as any)
220+
const temp_broker = broker as any;
222221

223222
// 1. Bybit-style method?
224223
if (typeof temp_broker.privateGetV5UserQueryApi === "function") {
225224
const query = await temp_broker.privateGetV5UserQueryApi();
225+
if (!query?.id || !query?.userID) {
226+
throw new Error("Invalid response structure from privateGetV5UserQueryApi");
227+
}
226228
accountId = query.id;
227229
uid = query.userID;
228230
// 2. MEXC-style method?
@@ -242,9 +244,10 @@ export function getServer(
242244
return callback(
243245
{
244246
code: grpc.status.INTERNAL,
245-
message: "Error: fetching account ID not supported for this broker",
247+
message:
248+
"Error: fetching account ID not supported for this broker",
246249
},
247-
null
250+
null,
248251
);
249252
}
250253

@@ -253,7 +256,6 @@ export function getServer(
253256
proof: verityProof,
254257
result: JSON.stringify({ accountId, uid }),
255258
});
256-
257259
} catch (error) {
258260
log.error(`Error fetching account ID ${cex}:`, error);
259261
callback(

0 commit comments

Comments
 (0)