From 5b254c3c823eff3ccfc92aaae47f2b984d4933ba Mon Sep 17 00:00:00 2001 From: Yoojin Ko Date: Wed, 20 Dec 2023 17:08:57 +0900 Subject: [PATCH] fix: throw error with reject --- src/controllers/serviceController.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/controllers/serviceController.ts b/src/controllers/serviceController.ts index f5bbfbe..3a450c8 100644 --- a/src/controllers/serviceController.ts +++ b/src/controllers/serviceController.ts @@ -81,16 +81,20 @@ export default class ServiceController { this.checkRunning(serviceName); const result = await new Promise(async (resolve, reject) => { const requestKey = Date.now(); - const requesterAddress = this.ain.getAddress(); - const responsePath = Path.app(serviceName).response(requesterAddress, requestKey.toString()); - await this.handler.subscribe(responsePath, resolve); - const requestPath = Path.app(serviceName).request(requesterAddress, requestKey); - const requestOp = buildSetOperation("SET_VALUE", requestPath, requestData); - const txBody = buildTxBody(requestOp); - await this.ain.sendTransaction(txBody); - return requestKey; + try { + const requesterAddress = this.ain.getAddress(); + const responsePath = Path.app(serviceName).response(requesterAddress, requestKey.toString()); + await this.handler.subscribe(responsePath, resolve); + const requestPath = Path.app(serviceName).request(requesterAddress, requestKey); + const requestOp = buildSetOperation("SET_VALUE", requestPath, requestData); + const txBody = buildTxBody(requestOp); + await this.ain.sendTransaction(txBody); + } catch (e: any) { + if (e instanceof Error) + return reject(new Error(e.message)); + } }); - return result as string; + return result; } async run(serviceName: string): Promise {