diff --git a/src/controller/keyword.controller.ts b/src/controller/keyword.controller.ts index 0b5611b..2a883d4 100644 --- a/src/controller/keyword.controller.ts +++ b/src/controller/keyword.controller.ts @@ -47,7 +47,10 @@ const getTopKeywords = async (req: Request, res: Response, next: NextFunction) = const topReactionImage: string = await MemeService.getTopReactionImage(keyword); return { ...keyword, topReactionImage } as IKeywordWithImage; } catch (error) { - logger.error(`Error retrieving top reaction image for keyword: ${keyword}`, error); + logger.error( + `Error retrieving top reaction image for keyword: ${JSON.stringify(keyword._id)}`, + error, + ); throw new CustomError(`Failed to get top reaction image`, HttpCode.INTERNAL_SERVER_ERROR); } }, diff --git a/src/service/meme.service.ts b/src/service/meme.service.ts index 9eb4774..985f670 100644 --- a/src/service/meme.service.ts +++ b/src/service/meme.service.ts @@ -285,10 +285,14 @@ async function getTopReactionImage(keyword: IKeywordDocument): Promise { reaction: -1, }); + if (_.isNull(topReactionMeme)) { + throw new CustomError(`Failed get top reaction meme image`, HttpCode.NOT_FOUND); + } + logger.info(`Get top reaction meme - keyword(${keyword.name}), meme(${topReactionMeme._id})`); return topReactionMeme.image; } catch (err) { - logger.error(`Failed get top reaction meme`, err.message); + logger.error(`Failed get top reaction meme image`, err.message); throw new CustomError( `Failed get top reaction meme(${err.message})`, HttpCode.INTERNAL_SERVER_ERROR,