fix: guard markdownToHtml in the HTML fallback path
A throw from the converter used to escape the try/catch and drop the message; degrade to plain text for that chunk instead.
This commit is contained in:
+7
-1
@@ -828,7 +828,13 @@ export class TelegramBridge {
|
|||||||
async deliverHtml(chatId, markdown) {
|
async deliverHtml(chatId, markdown) {
|
||||||
const chunks = splitMessage(markdown, this.maxMessageLength);
|
const chunks = splitMessage(markdown, this.maxMessageLength);
|
||||||
for (const chunk of chunks) {
|
for (const chunk of chunks) {
|
||||||
const html = markdownToHtml(chunk);
|
let html;
|
||||||
|
try {
|
||||||
|
html = markdownToHtml(chunk);
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
html = chunk; // Pathological markdown input: degrade to plain text instead of dropping.
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
await this.withRetry(() => this.client.sendMessage(chatId, html, 'HTML'));
|
await this.withRetry(() => this.client.sendMessage(chatId, html, 'HTML'));
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-1
@@ -954,7 +954,12 @@ export class TelegramBridge {
|
|||||||
private async deliverHtml(chatId: number, markdown: string): Promise<void> {
|
private async deliverHtml(chatId: number, markdown: string): Promise<void> {
|
||||||
const chunks = splitMessage(markdown, this.maxMessageLength)
|
const chunks = splitMessage(markdown, this.maxMessageLength)
|
||||||
for (const chunk of chunks) {
|
for (const chunk of chunks) {
|
||||||
const html = markdownToHtml(chunk)
|
let html: string
|
||||||
|
try {
|
||||||
|
html = markdownToHtml(chunk)
|
||||||
|
} catch {
|
||||||
|
html = chunk // Pathological markdown input: degrade to plain text instead of dropping.
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
await this.withRetry(() => this.client.sendMessage(chatId, html, 'HTML'))
|
await this.withRetry(() => this.client.sendMessage(chatId, html, 'HTML'))
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
Reference in New Issue
Block a user