diff --git a/src/__test__/integration/client.spec.ts b/src/__test__/integration/client.spec.ts index 5182eb45e..a915bede3 100644 --- a/src/__test__/integration/client.spec.ts +++ b/src/__test__/integration/client.spec.ts @@ -235,4 +235,63 @@ describe('Typescript usage suite', () => { // assert await expect(promise).rejects.toMatch('service failed internally'); }); + + it('Should throw correct message when calling non existing local service', async function () { + // arrange + client = await createClient(); + + // act + const res = getPeerExternalAddresses(client); + + // assert + await expect(res).rejects.toMatch( + "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=''", + ); + }); }); + +async function getPeerExternalAddresses(client: FluenceClient): Promise { + let request; + const promise = new Promise((resolve, reject) => { + request = new RequestFlowBuilder() + .withRawScript( + ` +(seq + (seq + (call %init_peer_id% ("getDataSrv" "relay") [] relay) + (call %init_peer_id% ("peer" "identify") [] res) + ) + (call %init_peer_id% ("callbackSrv" "response") [res.$.external_addresses!]) +) + + `, + ) + .configHandler((h) => { + h.on('getDataSrv', 'relay', () => { + return client.relayPeerId; + }); + h.on('getRelayService', 'hasReleay', () => { + // Not Used + return client.relayPeerId !== undefined; + }); + + h.on('callbackSrv', 'response', (args) => { + const [res] = args; + resolve(res); + }); + + h.on('nameOfServiceWhereToSendXorError', 'errorProbably', (args) => { + // assuming error is the single argument + const [err] = args; + reject(err); + }); + }) + .handleScriptError(reject) + .handleTimeout(() => { + reject('Request timed out'); + }) + .build(); + }); + await client.initiateFlow(request); + return promise; +} diff --git a/src/api.ts b/src/api.ts index 20b561637..0e3bfa359 100644 --- a/src/api.ts +++ b/src/api.ts @@ -72,13 +72,13 @@ const makeKey = (client: FluenceClient, serviceId: string, fnName: string) => { * @param { FluenceClient } client - The Fluence Client instance. * @param { string } serviceId - The identifier of service which would be used to make calls from Aquamarine * @param { string } fnName - The identifier of function which would be used to make calls from Aquamarine - * @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 + * @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 */ export const registerServiceFunction = ( client: FluenceClient, serviceId: string, fnName: string, - handler: (args: any[], tetraplets: SecurityTetraplet[][]) => object, + handler: (args: any[], tetraplets: SecurityTetraplet[][]) => any, ) => { const unregister = client.aquaCallHandler.on(serviceId, fnName, handler); handlersUnregistratorsMap.set(makeKey(client, serviceId, fnName), unregister); diff --git a/src/internal/AquaHandler.ts b/src/internal/AquaHandler.ts index 4cb7bdc3d..96fa22125 100644 --- a/src/internal/AquaHandler.ts +++ b/src/internal/AquaHandler.ts @@ -220,6 +220,7 @@ export class AquaCallHandler { execute(req: AquaCall): AquaCallResult { const res: AquaCallResult = { retCode: ResultCodes.unkownError, + 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}'`, }; this.buildFunction()(req, res); return res;