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 { 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/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, }); } 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'),