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 23, 2024
1 parent d14608d commit ac3461b
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 @@ -728,7 +728,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 @@ -742,7 +746,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 ac3461b

Please sign in to comment.