diff --git a/changelog.md b/changelog.md index 3556040..b520f3c 100644 --- a/changelog.md +++ b/changelog.md @@ -1,9 +1,13 @@ +1.6.2 +----- +- Feat: Streams do now support auto-reconnection for the initial connection attempt + 1.6.1 ----- -- Feat: New option for creating streams, `autoConnect` that is `true` by default. Setting the value to `false` will cause the `TweetStream` object to be returned immediately (not in a `Promise`), because connection isn't awaited. #92 -- Fix: `autoReconnectRetries`: Setting this params to `Infinity` no longer causes the stream reconnection attempts to be delayed to next event loop turn. #92 -- Fix: Use `https.request(options)` instead of `https.request(url, options)`, because some people has outdated dependencies that overwrite native Node's exported function and break its signature. #94 #96 -- Feat: Next retry timeout computation can be customized by using `.nextRetryTimeout` property of `TweetStream` instance, that is function taking a `tryOccurence` and returning the number of milliseconds to wait before trying to reconnect. +- Feat: New option for creating streams, `autoConnect` that is `true` by default ; Setting the value to `false` will cause the `TweetStream` object to be returned immediately (not in a `Promise`), because connection isn't awaited #92 +- Fix: `autoReconnectRetries`: Setting this params to `Infinity` no longer causes the stream reconnection attempts to be delayed to next event loop turn #92 +- Fix: Use `https.request(options)` instead of `https.request(url, options)`, because some people has outdated dependencies that overwrite native Node's exported function and break its signature #94 #96 +- Feat: Next retry timeout computation can be customized by using `.nextRetryTimeout` property of `TweetStream` instance, that is function taking a `tryOccurence` and returning the number of milliseconds to wait before trying to reconnect 1.6.0 ----- diff --git a/package.json b/package.json index 39bff06..2ba6590 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "twitter-api-v2", - "version": "1.6.1", + "version": "1.6.2", "description": "Strongly typed, full-featured, light, versatile yet powerful Twitter API v1.1 and v2 client for Node.js.", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/stream/TweetStream.ts b/src/stream/TweetStream.ts index 029c6a4..fc09616 100644 --- a/src/stream/TweetStream.ts +++ b/src/stream/TweetStream.ts @@ -10,6 +10,7 @@ interface ITweetStreamError { type: ETwitterStreamEvent.ConnectionError | ETwitterStreamEvent.TweetParseError | ETwitterStreamEvent.ReconnectError | ETwitterStreamEvent.DataError | ETwitterStreamEvent.ConnectError; error: any; + message?: string; } export interface IConnectTweetStreamParams { @@ -85,6 +86,7 @@ export class TweetStream extends EventEmitter { this.emit(ETwitterStreamEvent.Error, { type: ETwitterStreamEvent.ConnectionError, error: err, + message: 'Connection lost or closed by Twitter.', }); this.onConnectionError(); @@ -115,7 +117,11 @@ export class TweetStream extends EventEmitter { this.parser.on(EStreamParserEvent.ParsedData, (eventData: any) => { if (payloadIsError && payloadIsError(eventData)) { this.emit(ETwitterStreamEvent.DataError, eventData); - this.emit(ETwitterStreamEvent.Error, { type: ETwitterStreamEvent.DataError, error: eventData }); + this.emit(ETwitterStreamEvent.Error, { + type: ETwitterStreamEvent.DataError, + error: eventData, + message: 'Twitter sent a payload that is detected as an error payload.', + }); } else { this.emit(ETwitterStreamEvent.Data, eventData); @@ -127,6 +133,7 @@ export class TweetStream extends EventEmitter { this.emit(ETwitterStreamEvent.Error, { type: ETwitterStreamEvent.TweetParseError, error, + message: 'Failed to parse stream data.', }); }); } @@ -238,7 +245,8 @@ export class TweetStream extends EventEmitter { this.emit(ETwitterStreamEvent.ConnectError, 0); this.emit(ETwitterStreamEvent.Error, { type: ETwitterStreamEvent.ConnectError, - error: new Error(`Connect error - Initial connection just failed.`), + error: e, + message: 'Connect error - Initial connection just failed.', }); this.makeAutoReconnectRetry(0); @@ -296,7 +304,8 @@ export class TweetStream extends EventEmitter { this.emit(ETwitterStreamEvent.ReconnectError, retryOccurence); this.emit(ETwitterStreamEvent.Error, { type: ETwitterStreamEvent.ReconnectError, - error: new Error(`Reconnect error - ${retryOccurence + 1} attempts made yet.`), + error: e, + message: `Reconnect error - ${retryOccurence + 1} attempts made yet.`, }); this.makeAutoReconnectRetry(retryOccurence);