WS error logging & stacks trimmed (#448)

* Cleanup error stacks

* Close error code & reason

* Re-add debug throw

* Remove stack

* Cleanup console checks (bullsh*t, wtf did I add these anyway)
This commit is contained in:
Jaco Greeff
2018-12-07 10:07:20 +01:00
committed by GitHub
parent b9215d286f
commit 50103dcfab
5 changed files with 12 additions and 65 deletions
+6 -6
View File
@@ -216,7 +216,7 @@ export default class WsProvider implements WSProviderInterface {
// a slight complication in solving - since we cannot rely on the send id, but rather
// need to find the actual subscription id to map it
if (isUndefined(this.subscriptions[subscription])) {
l.warn(`Unable to find active subscription=${subscription}`);
l.debug(() => `Unable to find active subscription=${subscription}`);
return false;
}
@@ -232,8 +232,8 @@ export default class WsProvider implements WSProviderInterface {
this._eventemitter.emit(type, ...args);
}
private onSocketClose = (): void => {
l.debug(() => ['disconnected from', this.endpoint]);
private onSocketClose = (event: CloseEvent): void => {
l.error(`disconnected from ${this.endpoint}::${event.code}: ${event.reason}`);
this._isConnected = false;
this.emit('disconnected');
@@ -246,7 +246,7 @@ export default class WsProvider implements WSProviderInterface {
}
private onSocketError = (error: Event): void => {
l.error(error);
l.debug(() => ['socket error', error]);
}
private onSocketMessage = (message: MessageEvent): void => {
@@ -265,7 +265,7 @@ export default class WsProvider implements WSProviderInterface {
const handler = this.handlers[response.id];
if (!handler) {
l.error(`Unable to find handler for id=${response.id}`);
l.debug(() => `Unable to find handler for id=${response.id}`);
return;
}
@@ -297,7 +297,7 @@ export default class WsProvider implements WSProviderInterface {
const handler = this.subscriptions[subscription];
if (!handler) {
l.error(`Unable to find handler for subscription=${subscription}`);
l.debug(() => `Unable to find handler for subscription=${subscription}`);
return;
}
@@ -1,27 +0,0 @@
// Copyright 2017-2018 @polkadot/rpc-provider authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import Ws from './index';
describe('onError', () => {
let ws;
let errorSpy;
beforeEach(() => {
ws = new Ws('ws://127.0.0.1:1234', false);
errorSpy = jest.spyOn(console, 'error');
});
afterEach(() => {
errorSpy.mockRestore();
});
it('logs the error', () => {
ws.onSocketError('test error');
expect(errorSpy).toHaveBeenCalledWith(
expect.anything(), expect.anything(), 'test error'
);
});
});
@@ -6,23 +6,9 @@ import Ws from './index';
describe('onMessageResult', () => {
let ws;
let errorSpy;
beforeEach(() => {
ws = new Ws('ws://127.0.0.1:1234', false);
errorSpy = jest.spyOn(console, 'error');
});
afterEach(() => {
errorSpy.mockRestore();
});
it('fails with log when handler not found', () => {
ws.onSocketMessage({ data: '{"id":2}' });
expect(errorSpy).toHaveBeenCalledWith(
expect.anything(), expect.anything(), 'Unable to find handler for id=2'
);
});
it('calls the handler when found', (done) => {
@@ -6,23 +6,9 @@ import Ws from './index';
describe('onMessageSubscribe', () => {
let ws;
let errorSpy;
beforeEach(() => {
ws = new Ws('ws://127.0.0.1:1234', false);
errorSpy = jest.spyOn(console, 'error');
});
afterEach(() => {
errorSpy.mockRestore();
});
it('fails with log when handler not found', () => {
ws.onSocketMessage({ data: '{"method":"test","params":{"subscription":2}}' });
expect(errorSpy).toHaveBeenCalledWith(
expect.anything(), expect.anything(), 'Unable to find handler for subscription=test::2'
);
});
it('calls the subscriber with data', (done) => {