Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mobile/ios/lightning/LndReactModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 12 additions & 4 deletions src/action/grpc-mobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}) {
Expand Down
2 changes: 1 addition & 1 deletion src/action/payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
Expand Down
18 changes: 18 additions & 0 deletions test/unit/action/grpc-mobile.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down