[FIX] handle websocket errors in browsers

emit not RippledNotInitializedError if server doesn't have any
completed ledgers on connect
This commit is contained in:
Ivan Tivonenko
2016-03-29 20:31:54 +03:00
parent 14bbe3e30b
commit 5da78ce583
10 changed files with 236 additions and 96 deletions

View File

@@ -1,5 +1,5 @@
/* eslint-disable max-nested-callbacks */
'use strict';
'use strict'; // eslint-disable-line
const {RippleAPI, RippleAPIBroadcast} = require('ripple-api');
const ledgerClosed = require('./fixtures/rippled/ledger-close');
@@ -8,12 +8,22 @@ const port = 34371;
const baseUrl = 'ws://testripple.circleci.com:';
function setup(port_ = port) {
return new Promise((resolve, reject) => {
this.api = new RippleAPI({server: baseUrl + port_});
this.api.connect().then(() => {
this.api.once('ledger', () => resolve());
this.api.connection._ws.emit('message', JSON.stringify(ledgerClosed));
}).catch(reject);
const tapi = new RippleAPI({server: baseUrl + port_});
return tapi.connect().then(() => {
return tapi.connection.request({
command: 'test_command',
data: {openOnOtherPort: true}
});
}).then(got => {
return new Promise((resolve, reject) => {
this.api = new RippleAPI({server: baseUrl + got.port});
this.api.connect().then(() => {
this.api.once('ledger', () => resolve());
this.api.connection._ws.emit('message', JSON.stringify(ledgerClosed));
}).catch(reject);
});
}).then(() => {
return tapi.disconnect();
});
}
@@ -33,6 +43,7 @@ function teardown() {
if (this.api.isConnected()) {
return this.api.disconnect();
}
return undefined;
}
module.exports = {