Skip to content

Commit

Permalink
feat(fjage.js): changing agentsForService to also reject promise if n…
Browse files Browse the repository at this point in the history
…o response
  • Loading branch information
notthetup committed Jan 16, 2024
1 parent 937c93f commit 2d5045c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions gateways/js/src/fjage.js
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,11 @@ export class Gateway {
async agentForService(service) {
let rq = { action: 'agentForService', service: service };
let rsp = await this._msgTxRx(rq);
if (!rsp || !rsp.agentID) return;
if (!rsp) {
if (this._returnNullOnError) return null;
else throw new Error('Unable to get agent for service');
}
if (!rsp.agentID) return null;
return new AgentID(rsp.agentID, false, this);
}

Expand All @@ -737,7 +741,11 @@ export class Gateway {
let rq = { action: 'agentsForService', service: service };
let rsp = await this._msgTxRx(rq);
let aids = [];
if (!rsp || !Array.isArray(rsp.agentIDs)) return aids;
if (!rsp) {
if (this._returnNullOnError) return aids;
else throw new Error('Unable to get agents for service');
}
if (!Array.isArray(rsp.agentIDs)) return aids;
for (var i = 0; i < rsp.agentIDs.length; i++)
aids.push(new AgentID(rsp.agentIDs[i], false, this));
return aids;
Expand Down

0 comments on commit 2d5045c

Please sign in to comment.