Skip to content

Commit de0516f

Browse files
authored
fixes (#38)
* Fix error message when an incorrect service has been called. * Fix return type of the handler in registerServiceFunction
1 parent 480c8aa commit de0516f

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

src/__test__/integration/client.spec.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,4 +235,63 @@ describe('Typescript usage suite', () => {
235235
// assert
236236
await expect(promise).rejects.toMatch('service failed internally');
237237
});
238+
239+
it('Should throw correct message when calling non existing local service', async function () {
240+
// arrange
241+
client = await createClient();
242+
243+
// act
244+
const res = getPeerExternalAddresses(client);
245+
246+
// assert
247+
await expect(res).rejects.toMatch(
248+
"The handler did not set any result. Make sure you are calling the right peer and the handler has been registered. Original request data was: serviceId='peer' fnName='identify' args=''",
249+
);
250+
});
238251
});
252+
253+
async function getPeerExternalAddresses(client: FluenceClient): Promise<string[]> {
254+
let request;
255+
const promise = new Promise<string[]>((resolve, reject) => {
256+
request = new RequestFlowBuilder()
257+
.withRawScript(
258+
`
259+
(seq
260+
(seq
261+
(call %init_peer_id% ("getDataSrv" "relay") [] relay)
262+
(call %init_peer_id% ("peer" "identify") [] res)
263+
)
264+
(call %init_peer_id% ("callbackSrv" "response") [res.$.external_addresses!])
265+
)
266+
267+
`,
268+
)
269+
.configHandler((h) => {
270+
h.on('getDataSrv', 'relay', () => {
271+
return client.relayPeerId;
272+
});
273+
h.on('getRelayService', 'hasReleay', () => {
274+
// Not Used
275+
return client.relayPeerId !== undefined;
276+
});
277+
278+
h.on('callbackSrv', 'response', (args) => {
279+
const [res] = args;
280+
resolve(res);
281+
});
282+
283+
h.on('nameOfServiceWhereToSendXorError', 'errorProbably', (args) => {
284+
// assuming error is the single argument
285+
const [err] = args;
286+
reject(err);
287+
});
288+
})
289+
.handleScriptError(reject)
290+
.handleTimeout(() => {
291+
reject('Request timed out');
292+
})
293+
.build();
294+
});
295+
await client.initiateFlow(request);
296+
return promise;
297+
}

src/api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ const makeKey = (client: FluenceClient, serviceId: string, fnName: string) => {
7272
* @param { FluenceClient } client - The Fluence Client instance.
7373
* @param { string } serviceId - The identifier of service which would be used to make calls from Aquamarine
7474
* @param { string } fnName - The identifier of function which would be used to make calls from Aquamarine
75-
* @param { (args: any[], tetraplets: SecurityTetraplet[][]) => object } handler - The handler which would be called by Aquamarine infrastructure. The result is any object passed back to Aquamarine
75+
* @param { (args: any[], tetraplets: SecurityTetraplet[][]) => any } handler - The handler which would be called by Aquamarine infrastructure. The result is any object passed back to Aquamarine
7676
*/
7777
export const registerServiceFunction = (
7878
client: FluenceClient,
7979
serviceId: string,
8080
fnName: string,
81-
handler: (args: any[], tetraplets: SecurityTetraplet[][]) => object,
81+
handler: (args: any[], tetraplets: SecurityTetraplet[][]) => any,
8282
) => {
8383
const unregister = client.aquaCallHandler.on(serviceId, fnName, handler);
8484
handlersUnregistratorsMap.set(makeKey(client, serviceId, fnName), unregister);

src/internal/AquaHandler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ export class AquaCallHandler {
220220
execute(req: AquaCall): AquaCallResult {
221221
const res: AquaCallResult = {
222222
retCode: ResultCodes.unkownError,
223+
result: `The handler did not set any result. Make sure you are calling the right peer and the handler has been registered. Original request data was: serviceId='${req.serviceId}' fnName='${req.fnName}' args='${req.args}'`,
223224
};
224225
this.buildFunction()(req, res);
225226
return res;

0 commit comments

Comments
 (0)