Add ignore other event types and more error logging

This commit is contained in:
Henrik Hüttemann 2023-08-31 18:59:53 +02:00
parent d711b81f23
commit b5605e64f7
No known key found for this signature in database
GPG Key ID: 9F7BD10E0A8A111E
2 changed files with 16 additions and 3 deletions

View File

@ -9,6 +9,7 @@ import log from './helpers/logger'
import { initStorage } from './helpers/storage'
import { whoami } from './helpers/synapse'
import { Entity, entities } from './Entities'
import { AxiosError } from 'axios'
log.info('rocketchat2matrix starts.')
@ -49,7 +50,13 @@ async function main() {
await loadRcExport(Entity.Messages)
log.info('Done.')
} catch (error) {
log.error(`Encountered an error while booting up: ${error}`, error)
if (error instanceof AxiosError) {
log.error(`Error during request: ${error.message}`)
log.error(`Request: ${error.request?.method} ${error.request?.path}`)
log.error(`Response: ${error.response?.status}`, error.response?.data)
} else {
log.error(`Encountered an error while booting up: ${error}`, error)
}
}
}

View File

@ -13,6 +13,7 @@ if (!applicationServiceToken) {
export type RcMessage = {
_id: string
t?: string // Event type
rid: string // The unique id for the room
msg: string // The content of the message.
tmid?: string
@ -84,9 +85,14 @@ export async function createMessage(
}
export async function handle(rcMessage: RcMessage): Promise<void> {
if (rcMessage.t) {
log.warn(`Message ${rcMessage._id} is of type ${rcMessage.t}, skipping.`)
return
}
const room_id = (await getRoomId(rcMessage.rid)) || ''
if (!room_id) {
log.info(
log.warn(
`Could not find room ${rcMessage.rid} for message ${rcMessage._id}, skipping.`
)
return
@ -94,7 +100,7 @@ export async function handle(rcMessage: RcMessage): Promise<void> {
const user_id = (await getUserId(rcMessage.u._id)) || ''
if (!user_id) {
log.info(
log.warn(
`Could not find author ${rcMessage.u.username} for message ${rcMessage._id}, skipping.`
)
return