diff --git a/src/bot.ts b/src/bot.ts index 8051c0b3c4190955ef6012f4e39ec5613f8ede6f..400bf1f146a7864baa2b02ab6cddc7b9b1f25821 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -19,8 +19,15 @@ import { DiscordClientFactory } from "./clientfactory"; import { DiscordStore } from "./store"; import { DbEmoji } from "./db/dbdataemoji"; import { DbEvent } from "./db/dbdataevent"; -import { MatrixUser, RemoteUser, Bridge, Entry, Intent } from "matrix-appservice-bridge"; -import { Util } from "./util"; +import { + Bridge, + Entry, + Intent, + MatrixUser, + RemoteUser, + unstable, +} from "matrix-appservice-bridge"; +import { Util, wrap } from "./util"; import { DiscordMessageProcessor, DiscordMessageProcessorOpts, @@ -423,6 +430,10 @@ export class DiscordBot { this.unlockChannel(channel); } + /** + * Sends an event to Discord. + * @throws {unstable.ForeignNetworkError} + */ public async send( embedSet: IMatrixEventProcessorResult, opts: Discord.MessageOptions, @@ -447,7 +458,7 @@ export class DiscordBot { "Matrix Bridge: Allow rich user messages"); } } catch (err) { - log.error("Unable to create \"_matrix\" webhook. ", err); + throw wrap(err, unstable.ForeignNetworkError, "Unable to create \"_matrix\" webhook"); } } try { @@ -474,7 +485,7 @@ export class DiscordBot { await this.StoreMessagesSent(msg, chan, event); this.unlockChannel(chan); } catch (err) { - log.error("Couldn't send message. ", err); + throw wrap(err, unstable.ForeignNetworkError, "Couldn't send message"); } } diff --git a/src/matrixeventprocessor.ts b/src/matrixeventprocessor.ts index 4979082adcbe8c1e63dd7a758eb16d3a55ca4082..461a4f034d1c3a624f823b5fe74402483b251fc3 100644 --- a/src/matrixeventprocessor.ts +++ b/src/matrixeventprocessor.ts @@ -131,11 +131,7 @@ export class MatrixEventProcessor { if (isBotCommand(event)) { await this.mxCommandHandler.Process(event, context); } else { - try { - await this.ProcessMsgEvent(event, context); - } catch (err) { - throw wrap(err, Error, "There was an error sending a matrix event"); - } + await this.ProcessMsgEvent(event, context); } return; } else if (event.type === "m.room.encryption" && context.rooms.remote) { @@ -175,6 +171,7 @@ export class MatrixEventProcessor { * * @param event The message event to process. * @param context Context of the bridge. + * @throws {unstable.ForeignNetworkError} */ public async ProcessMsgEvent(event: IMatrixEvent, context: BridgeContext): Promise<void> { const room = context.rooms.remote; @@ -199,7 +196,7 @@ export class MatrixEventProcessor { opts.file = file; } - await this.discord.send(embedSet, opts, roomLookup, event); + await this.discord.send(embedSet, opts, roomLookup, event); // throws await this.sendReadReceipt(event); }