Skip to content

Commit 45d109a

Browse files
committed
Fixed an issue where late bound connectors weren't getting setup as storage.
1 parent f8bd560 commit 45d109a

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

Node/core/src/bots/UniversalBot.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,6 @@ export class UniversalBot extends events.EventEmitter {
108108

109109
if (connector) {
110110
this.connector(consts.defaultConnector, connector);
111-
var asStorage: bs.IBotStorage = <any>connector;
112-
if (!this.settings.storage &&
113-
typeof asStorage.getData === 'function' &&
114-
typeof asStorage.saveData === 'function') {
115-
this.settings.storage = asStorage;
116-
}
117111
}
118112
}
119113

@@ -137,8 +131,17 @@ export class UniversalBot extends events.EventEmitter {
137131
public connector(channelId: string, connector?: IConnector): IConnector {
138132
var c: IConnector;
139133
if (connector) {
134+
// Bind to connector.
140135
this.connectors[channelId || consts.defaultConnector] = c = connector;
141136
c.onEvent((events, cb) => this.receive(events, cb));
137+
138+
// Optionally use connector for storage.
139+
var asStorage: bs.IBotStorage = <any>connector;
140+
if (!this.settings.storage &&
141+
typeof asStorage.getData === 'function' &&
142+
typeof asStorage.saveData === 'function') {
143+
this.settings.storage = asStorage;
144+
}
142145
} else if (this.connectors.hasOwnProperty(channelId)) {
143146
c = this.connectors[channelId];
144147
} else if (this.connectors.hasOwnProperty(consts.defaultConnector)) {
@@ -522,7 +525,8 @@ export class UniversalBot extends events.EventEmitter {
522525
}
523526

524527
private emitError(err: Error): void {
525-
var e = err instanceof Error ? err : new Error(err.toString());
528+
var m = err.toString();
529+
var e = err instanceof Error ? err : new Error(m);
526530
if (this.listenerCount('error') > 0) {
527531
this.emit('error', e);
528532
} else {

0 commit comments

Comments
 (0)