From 724ba3a729d1add1e489c42c1d2199a39163a9d8 Mon Sep 17 00:00:00 2001 From: Kevin Aleman Date: Thu, 9 May 2024 10:18:08 -0600 Subject: [PATCH] fix(pdf-transcript): Don't error out when trying to process an image bigger than NATS max payload (#32318) --- .changeset/silly-clocks-return.md | 7 +++++++ .../src/OmnichannelTranscript.ts | 17 +++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 .changeset/silly-clocks-return.md diff --git a/.changeset/silly-clocks-return.md b/.changeset/silly-clocks-return.md new file mode 100644 index 000000000000..0505580a477a --- /dev/null +++ b/.changeset/silly-clocks-return.md @@ -0,0 +1,7 @@ +--- +'@rocket.chat/omnichannel-services': patch +'@rocket.chat/core-services': patch +'@rocket.chat/meteor': patch +--- + +Fixed error handling for files bigger than NATS max allowed payload. This should prevent PDFs from erroring out when generating from rooms that contain heavy images. diff --git a/ee/packages/omnichannel-services/src/OmnichannelTranscript.ts b/ee/packages/omnichannel-services/src/OmnichannelTranscript.ts index 02816b7aebc3..2d273991508b 100644 --- a/ee/packages/omnichannel-services/src/OmnichannelTranscript.ts +++ b/ee/packages/omnichannel-services/src/OmnichannelTranscript.ts @@ -232,8 +232,21 @@ export class OmnichannelTranscript extends ServiceClass implements IOmnichannelT continue; } - const fileBuffer = await uploadService.getFileBuffer({ file: uploadedFile }); - files.push({ name: file.name, buffer: fileBuffer, extension: uploadedFile.extension }); + try { + const fileBuffer = await uploadService.getFileBuffer({ file: uploadedFile }); + files.push({ name: file.name, buffer: fileBuffer, extension: uploadedFile.extension }); + } catch (e: unknown) { + this.log.error(`Failed to get file ${file._id}`, e); + // Push empty buffer so parser processes this as "unsupported file" + files.push({ name: file.name, buffer: null }); + + // TODO: this is a NATS error message, even when we shouldn't tie it, since it's the only way we have right now we'll live with it for a while + if ((e as Error).message === 'MAX_PAYLOAD_EXCEEDED') { + this.log.error( + `File is too big to be processed by NATS. See NATS config for allowing bigger messages to be sent between services`, + ); + } + } } // When you send a file message, the things you type in the modal are not "msg", they're in "description" of the attachment