From 603a80d3a756323478c4b7d4267186b440d6d483 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Mon, 12 Aug 2019 13:57:52 +0200 Subject: [PATCH 1/3] Return string error message on iOS LndReactNativeModule.m --- mobile/ios/lightning/LndReactModule.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mobile/ios/lightning/LndReactModule.m b/mobile/ios/lightning/LndReactModule.m index c7e763b9a..bf6d07473 100644 --- a/mobile/ios/lightning/LndReactModule.m +++ b/mobile/ios/lightning/LndReactModule.m @@ -38,7 +38,7 @@ - (instancetype)initWithResolver: (RCTPromiseResolveBlock)resolve rejecter:(RCTP } - (void)onError:(NSError *)p0 { - self.reject(@"error", @"received error", p0); + self.reject(@"error", [p0 localizedDescription], p0); } - (void)onResponse:(NSData *)p0 { From 56d0574e13285986f82f97f59b2078023d9c4b2c Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Mon, 12 Aug 2019 13:59:01 +0200 Subject: [PATCH 2/3] Wrap error strings thrown in Error objects in grpc-mobile.js --- src/action/grpc-mobile.js | 16 ++++++++++++---- test/unit/action/grpc-mobile.spec.js | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/action/grpc-mobile.js b/src/action/grpc-mobile.js index 60a4f9793..e310f3a67 100644 --- a/src/action/grpc-mobile.js +++ b/src/action/grpc-mobile.js @@ -165,10 +165,18 @@ class GrpcAction { // async _lnrpcRequest(method, body) { - method = toCaps(method); - const req = this._serializeRequest(method, body); - const response = await this._lnd.sendCommand(method, req); - return this._deserializeResponse(method, response.data); + try { + method = toCaps(method); + const req = this._serializeRequest(method, body); + const response = await this._lnd.sendCommand(method, req); + return this._deserializeResponse(method, response.data); + } catch (err) { + if (typeof err === 'string') { + throw new Error(err); + } else { + throw err; + } + } } _serializeRequest(method, body = {}) { diff --git a/test/unit/action/grpc-mobile.spec.js b/test/unit/action/grpc-mobile.spec.js index ad502a1c8..fe3285b8e 100644 --- a/test/unit/action/grpc-mobile.spec.js +++ b/test/unit/action/grpc-mobile.spec.js @@ -161,6 +161,24 @@ describe('Action GRPC Mobile Unit Tests', () => { }); describe('sendCommand()', () => { + it('should handle string error mesage', async () => { + LndReactModuleStub.sendCommand.returns(Promise.reject('some-message')); + await expect( + grpc.sendCommand('GetInfo'), + 'to be rejected with error satisfying', + /some-message/ + ); + }); + + it('should handle error object', async () => { + LndReactModuleStub.sendCommand.rejects(new Error('some-message')); + await expect( + grpc.sendCommand('GetInfo'), + 'to be rejected with error satisfying', + /some-message/ + ); + }); + it('should work for GetInfo (without body)', async () => { LndReactModuleStub.sendCommand.resolves({ data: grpc._serializeResponse('GetInfo'), From 13af394cdf583102e066a043db02ee1b17fd025e Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Mon, 12 Aug 2019 13:59:32 +0200 Subject: [PATCH 3/3] Use standard error message in error notification when fee estimation failed --- src/action/payment.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/action/payment.js b/src/action/payment.js index 1d277112e..114ec6243 100644 --- a/src/action/payment.js +++ b/src/action/payment.js @@ -247,7 +247,7 @@ class PaymentAction { this._nav.goPayBitcoinConfirm(); } catch (err) { this._notification.display({ - msg: `Fee estimation failed: ${err.details}`, + msg: `Fee estimation failed: ${err.message}`, err, }); }