diff --git a/src/d2m/event-dispatcher.js b/src/d2m/event-dispatcher.js index c25d1c6..3392eb9 100644 --- a/src/d2m/event-dispatcher.js +++ b/src/d2m/event-dispatcher.js @@ -51,13 +51,15 @@ module.exports = { * @param {import("cloudstorm").IGatewayMessage} gatewayMessage */ async onError(client, e, gatewayMessage) { + if (gatewayMessage.t === "TYPING_START") return + + matrixEventDispatcher.printError(gatewayMessage.t, "Discord", e, gatewayMessage) + const channelID = gatewayMessage.d["channel_id"] if (!channelID) return const roomID = select("channel_room", "room_id", {channel_id: channelID}).pluck().get() if (!roomID) return - if (gatewayMessage.t === "TYPING_START") return - await matrixEventDispatcher.sendError(roomID, "Discord", gatewayMessage.t, e, gatewayMessage) }, diff --git a/src/m2d/event-dispatcher.js b/src/m2d/event-dispatcher.js index 48bff11..57c0fa6 100644 --- a/src/m2d/event-dispatcher.js +++ b/src/m2d/event-dispatcher.js @@ -88,6 +88,12 @@ function stringifyErrorStack(err, depth = 0) { return collapsed; } +function printError(type, source, e, payload) { + console.error(`Error while processing a ${type} ${source} event:`) + console.error(e) + console.dir(payload, {depth: null}) +} + /** * @param {string} roomID * @param {"Discord" | "Matrix"} source @@ -96,9 +102,9 @@ function stringifyErrorStack(err, depth = 0) { * @param {any} payload */ async function sendError(roomID, source, type, e, payload) { - console.error(`Error while processing a ${type} ${source} event:`) - console.error(e) - console.dir(payload, {depth: null}) + if (source === "Matrix") { + printError(type, source, e, payload) + } if (Date.now() - lastReportedEvent < 5000) return null lastReportedEvent = Date.now() @@ -457,3 +463,4 @@ async event => { module.exports.stringifyErrorStack = stringifyErrorStack module.exports.sendError = sendError +module.exports.printError = printError