Skip to content

Commit

Permalink
doc: Bumped changelog & improved streams errors
Browse files Browse the repository at this point in the history
  • Loading branch information
alkihis committed Oct 21, 2021
1 parent 6db20ce commit 39df704
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
12 changes: 8 additions & 4 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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
-----
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
15 changes: 12 additions & 3 deletions src/stream/TweetStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface ITweetStreamError {
type: ETwitterStreamEvent.ConnectionError | ETwitterStreamEvent.TweetParseError
| ETwitterStreamEvent.ReconnectError | ETwitterStreamEvent.DataError | ETwitterStreamEvent.ConnectError;
error: any;
message?: string;
}

export interface IConnectTweetStreamParams {
Expand Down Expand Up @@ -85,6 +86,7 @@ export class TweetStream<T = any> extends EventEmitter {
this.emit(ETwitterStreamEvent.Error, {
type: ETwitterStreamEvent.ConnectionError,
error: err,
message: 'Connection lost or closed by Twitter.',
});

this.onConnectionError();
Expand Down Expand Up @@ -115,7 +117,11 @@ export class TweetStream<T = any> 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);
Expand All @@ -127,6 +133,7 @@ export class TweetStream<T = any> extends EventEmitter {
this.emit(ETwitterStreamEvent.Error, {
type: ETwitterStreamEvent.TweetParseError,
error,
message: 'Failed to parse stream data.',
});
});
}
Expand Down Expand Up @@ -238,7 +245,8 @@ export class TweetStream<T = any> 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);
Expand Down Expand Up @@ -296,7 +304,8 @@ export class TweetStream<T = any> 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);
Expand Down

0 comments on commit 39df704

Please sign in to comment.