Fix feed.success crashing the process due to a typing issue (#469)

* Fix feed.sucess

* changelog

* Stop being lazy and use an interface
This commit is contained in:
Will Hunt 2022-09-02 15:46:20 +01:00 committed by GitHub
parent e0dadd4ad3
commit 79f28f3ae0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 5 deletions

1
changelog.d/469.bugfix Normal file
View File

@ -0,0 +1 @@
Fix a bug where reading RSS feeds could crash the process.

View File

@ -40,7 +40,7 @@ import { getAppservice } from "./appservice";
import { JiraOAuthRequestCloud, JiraOAuthRequestOnPrem, JiraOAuthRequestResult } from "./Jira/OAuth";
import { GenericWebhookEvent, GenericWebhookEventResult } from "./generic/types";
import { SetupWidget } from "./Widgets/SetupWidget";
import { FeedEntry, FeedError, FeedReader } from "./feeds/FeedReader";
import { FeedEntry, FeedError, FeedReader, FeedSuccess } from "./feeds/FeedReader";
const log = new LogWrapper("Bridge");
export class Bridge {
@ -615,9 +615,9 @@ export class Bridge {
(data) => connManager.getConnectionsForFeedUrl(data.feed.url),
(c, data) => c.handleFeedEntry(data),
);
this.bindHandlerToQueue<FeedEntry, FeedConnection>(
this.bindHandlerToQueue<FeedSuccess, FeedConnection>(
"feed.success",
(data) => connManager.getConnectionsForFeedUrl(data.feed.url),
(data) => connManager.getConnectionsForFeedUrl(data.url),
c => c.handleFeedSuccess(),
);
this.bindHandlerToQueue<FeedError, FeedConnection>(

View File

@ -55,6 +55,10 @@ export interface FeedEntry {
fetchKey: string,
}
export interface FeedSuccess {
url: string,
}
interface AccountData {
[url: string]: string[],
}
@ -210,7 +214,7 @@ export class FeedReader {
const entry = {
feed: {
title: feed.title ? stripHtml(feed.title) : null,
url: url.toString()
url: url,
},
title: item.title ? stripHtml(item.title) : null,
link: item.link || null,
@ -233,7 +237,7 @@ export class FeedReader {
const newSeenItems = Array.from(new Set([ ...newGuids, ...seenGuids ]).values()).slice(0, maxGuids);
this.seenEntries.set(url, newSeenItems);
}
this.queue.push<undefined>({ eventName: 'feed.success', sender: 'FeedReader', data: undefined});
this.queue.push<FeedSuccess>({ eventName: 'feed.success', sender: 'FeedReader', data: { url: url } });
} catch (err: unknown) {
const error = err instanceof Error ? err : new Error(`Unknown error ${err}`);
const feedError = new FeedError(url.toString(), error, fetchKey);