feat: log thumb gen errors

This commit is contained in:
Adhiraj Singh
2022-09-12 12:15:34 +05:30
parent c20865dff1
commit 64f3f08adb
2 changed files with 9 additions and 2 deletions

View File

@@ -607,7 +607,8 @@ export const makeMessagesSocket = (config: SocketConfig) => {
userJid, userJid,
getUrlInfo: text => getUrlInfo( getUrlInfo: text => getUrlInfo(
text, text,
{ thumbnailWidth: linkPreviewImageThumbnailWidth, timeoutMs: 3_000 } { thumbnailWidth: linkPreviewImageThumbnailWidth, timeoutMs: 3_000 },
logger
), ),
upload: waUploadToServer, upload: waUploadToServer,
mediaCache: config.mediaCache, mediaCache: config.mediaCache,

View File

@@ -1,3 +1,4 @@
import { Logger } from 'pino'
import { WAUrlInfo } from '../Types' import { WAUrlInfo } from '../Types'
import { extractImageThumb, getHttpStream } from './messages-media' import { extractImageThumb, getHttpStream } from './messages-media'
@@ -23,7 +24,8 @@ export type URLGenerationOptions = {
*/ */
export const getUrlInfo = async( export const getUrlInfo = async(
text: string, text: string,
opts: URLGenerationOptions = { thumbnailWidth: THUMBNAIL_WIDTH_PX, timeoutMs: 3000 } opts: URLGenerationOptions = { thumbnailWidth: THUMBNAIL_WIDTH_PX, timeoutMs: 3000 },
logger?: Logger
): Promise<WAUrlInfo | undefined> => { ): Promise<WAUrlInfo | undefined> => {
try { try {
const { getLinkPreview } = await import('link-preview-js') const { getLinkPreview } = await import('link-preview-js')
@@ -42,6 +44,10 @@ export const getUrlInfo = async(
? await getCompressedJpegThumbnail(image, opts) ? await getCompressedJpegThumbnail(image, opts)
: undefined : undefined
} catch(error) { } catch(error) {
logger?.debug(
{ err: error.stack, url: previewLink },
'error in generating thumbnail'
)
} }
return { return {