mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
[FIX] handle websocket errors in browsers
emit not RippledNotInitializedError if server doesn't have any completed ledgers on connect
This commit is contained in:
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user