From 64f3f08adbaacb87c545c59d27d550cad08e393a Mon Sep 17 00:00:00 2001 From: Adhiraj Singh Date: Mon, 12 Sep 2022 12:15:34 +0530 Subject: [PATCH] feat: log thumb gen errors --- src/Socket/messages-send.ts | 3 ++- src/Utils/link-preview.ts | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Socket/messages-send.ts b/src/Socket/messages-send.ts index 3121651..21f955a 100644 --- a/src/Socket/messages-send.ts +++ b/src/Socket/messages-send.ts @@ -607,7 +607,8 @@ export const makeMessagesSocket = (config: SocketConfig) => { userJid, getUrlInfo: text => getUrlInfo( text, - { thumbnailWidth: linkPreviewImageThumbnailWidth, timeoutMs: 3_000 } + { thumbnailWidth: linkPreviewImageThumbnailWidth, timeoutMs: 3_000 }, + logger ), upload: waUploadToServer, mediaCache: config.mediaCache, diff --git a/src/Utils/link-preview.ts b/src/Utils/link-preview.ts index 395c563..12f976a 100644 --- a/src/Utils/link-preview.ts +++ b/src/Utils/link-preview.ts @@ -1,3 +1,4 @@ +import { Logger } from 'pino' import { WAUrlInfo } from '../Types' import { extractImageThumb, getHttpStream } from './messages-media' @@ -23,7 +24,8 @@ export type URLGenerationOptions = { */ export const getUrlInfo = async( text: string, - opts: URLGenerationOptions = { thumbnailWidth: THUMBNAIL_WIDTH_PX, timeoutMs: 3000 } + opts: URLGenerationOptions = { thumbnailWidth: THUMBNAIL_WIDTH_PX, timeoutMs: 3000 }, + logger?: Logger ): Promise => { try { const { getLinkPreview } = await import('link-preview-js') @@ -42,6 +44,10 @@ export const getUrlInfo = async( ? await getCompressedJpegThumbnail(image, opts) : undefined } catch(error) { + logger?.debug( + { err: error.stack, url: previewLink }, + 'error in generating thumbnail' + ) } return {