Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

불필요한 로그 제거 #49

Merged
merged 2 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/controller/keyword.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@ const getTopKeywords = async (req: Request, res: Response, next: NextFunction) =
try {
const topReactionImage: string = await MemeService.getTopReactionImage(keyword);
return { ...keyword, topReactionImage } as IKeywordWithImage;
} catch (error) {
logger.error(
`Error retrieving top reaction image for keyword: ${JSON.stringify(keyword._id)}`,
error,
} catch (err) {
throw new CustomError(
`Error retrieving top reaction image for keyword: ${JSON.stringify(keyword._id)}: ${err.message}`,
HttpCode.INTERNAL_SERVER_ERROR,
);
throw new CustomError(`Failed to get top reaction image`, HttpCode.INTERNAL_SERVER_ERROR);
}
},
);
Expand Down
4 changes: 2 additions & 2 deletions src/controller/keywordCategory.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const updateKeywordCategory = async (req: CustomRequest, res: Response, next: Ne
updateInfo,
);
logger.info(`Updated category with ID ${req.params.categoryName}`);
return res.json(createSuccessResponse(HttpCode.OK, 'Update KeywordCategor', updatedCategory));
return res.json(createSuccessResponse(HttpCode.OK, 'Updated KeywordCategory', updatedCategory));
} catch (err) {
return next(new CustomError(err.message, err.status || HttpCode.INTERNAL_SERVER_ERROR));
}
Expand All @@ -40,7 +40,7 @@ const deleteKeywordCategory = async (req: CustomRequest, res: Response, next: Ne
const category = req.requestedKeywordCategory;
try {
await KeywordCategoryService.deleteKeywordCategory(category.name);
return res.json(createSuccessResponse(HttpCode.OK, 'Deleted KeywordCategor', true));
return res.json(createSuccessResponse(HttpCode.OK, 'Deleted KeywordCategory', true));
} catch (err) {
return next(new CustomError(err.message, err.status || HttpCode.INTERNAL_SERVER_ERROR));
}
Expand Down
2 changes: 1 addition & 1 deletion src/controller/meme.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const getMeme = async (req: Request, res: Response, next: NextFunction) => {
}

if (!mongoose.Types.ObjectId.isValid(memeId)) {
return next(new CustomError(`'memeId' is not a valid ObjectId`, HttpCode.BAD_REQUEST));
return next(new CustomError(`${memeId} is not a valid ObjectId`, HttpCode.BAD_REQUEST));
}

try {
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/requestedInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const getRequestedMemeInfo = async (
}

if (!mongoose.Types.ObjectId.isValid(memeId)) {
return next(new CustomError(`'memeId' is not a valid ObjectId`, HttpCode.BAD_REQUEST));
return next(new CustomError(`${memeId} is not a valid ObjectId`, HttpCode.BAD_REQUEST));
}

const meme: IMemeDocument = await getMeme(memeId);
Expand Down
42 changes: 24 additions & 18 deletions src/service/keyword.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ async function createKeyword(info: IKeywordCreatePayload): Promise<IKeywordDocum

return newKeywordObj;
} catch (err) {
logger.error(`Failed to create keyword ${info.name}: ${err.message}`);
throw new CustomError('Failed to create keyword', HttpCode.INTERNAL_SERVER_ERROR);
throw new CustomError(
`Failed to create keyword ${info.name}: ${err.message}`,
HttpCode.INTERNAL_SERVER_ERROR,
);
}
}

Expand All @@ -41,16 +43,17 @@ async function updateKeyword(
).lean();

if (_.isNull(updatedKeyword)) {
throw new CustomError(`Keyword with ID ${keywordId} not found`, HttpCode.NOT_FOUND);
throw new CustomError(`Keyword(${keywordId}) not found`, HttpCode.NOT_FOUND);
}

logger.info(`Update keyword - keyword(${keywordId})`);
logger.info(`Update keyword - Keyword(${keywordId})`);
return updatedKeyword;
}

async function deleteKeyword(keywordId: Types.ObjectId): Promise<boolean> {
const deletedKeyword = await KeywordModel.findOneAndDelete({ _id: keywordId }).lean();
if (_.isNull(deletedKeyword)) {
throw new CustomError(`Keyword with ID ${keywordId} not found`, HttpCode.NOT_FOUND);
throw new CustomError(`Keyword(${keywordId}) not found`, HttpCode.NOT_FOUND);
}
return true;
}
Expand All @@ -63,8 +66,10 @@ async function getTopKeywords(limit: number = 6): Promise<IKeywordDocument[]> {
.lean();
return topKeywords;
} catch (err) {
logger.error(`Failed to get top keywords: ${err.message}`);
throw new CustomError('Failed to get top keywords', HttpCode.INTERNAL_SERVER_ERROR);
throw new CustomError(
`Failed to get top keywords: ${err.message}`,
HttpCode.INTERNAL_SERVER_ERROR,
);
}
}

Expand All @@ -76,12 +81,14 @@ async function increaseSearchCount(keywordId: Types.ObjectId): Promise<IKeywordD
{ new: true, projection: { isDeleted: 0 } },
).lean();
if (_.isNull(updatedKeyword)) {
throw new CustomError(`KeywordId ${keywordId} not found`, HttpCode.NOT_FOUND);
throw new CustomError(`KeywordId(${keywordId}) not found`, HttpCode.NOT_FOUND);
}
return updatedKeyword;
} catch (err) {
logger.error(`Failed to increase searchCount for keywordId ${keywordId}: ${err.message}`);
throw new CustomError('Failed to increase searchCount', HttpCode.INTERNAL_SERVER_ERROR);
throw new CustomError(
`Failed to increase searchCount for keywordId ${keywordId}: ${err.message}`,
HttpCode.INTERNAL_SERVER_ERROR,
);
}
}

Expand All @@ -90,9 +97,8 @@ async function getKeywordByName(keywordName: string): Promise<IKeywordDocument |
const keyword = await KeywordModel.findOne({ name: keywordName, isDeleted: false }).lean();
return keyword || null;
} catch (err) {
logger.error(`Failed to get a Keyword Info By Name(${keywordName})`);
throw new CustomError(
`Failed to get a Keyword Info By Name(${keywordName}) (${err.message})`,
`Failed to get a Keyword Info By Name(${keywordName}): ${err.message}`,
HttpCode.INTERNAL_SERVER_ERROR,
);
}
Expand All @@ -103,9 +109,8 @@ async function getKeywordById(keywordId: Types.ObjectId): Promise<IKeywordDocume
const keyword = await KeywordModel.findOne({ _id: keywordId, isDeleted: false }).lean();
return keyword || null;
} catch (err) {
logger.info(`Failed to get a Keyword Info By id (${keywordId})`);
throw new CustomError(
`Failed to get a Keyword Info By id(${keywordId}) (${err.message})`,
`Failed to get a Keyword Info By id(${keywordId}): ${err.message}`,
HttpCode.INTERNAL_SERVER_ERROR,
);
}
Expand All @@ -124,9 +129,8 @@ async function getKeywordInfoByKeywordIds(
).lean();
return keyword;
} catch (err) {
logger.error(`Failed to get a Keyword Info By keywordIds(${JSON.stringify(keywordIds)})`);
throw new CustomError(
`Failed to get a Keyword Info By keywordIds(${JSON.stringify(keywordIds)})`,
`Failed to get a Keyword Info By keywordIds(${JSON.stringify(keywordIds)}): ${err.message}`,
HttpCode.INTERNAL_SERVER_ERROR,
);
}
Expand Down Expand Up @@ -172,8 +176,10 @@ async function getRecommendedKeywords(): Promise<
logger.info('Successfully retrieved recommended keywords');
return result;
} catch (err) {
logger.error(`Failed to get recommended keywords: ${err.message}`);
throw new CustomError('Failed to get recommended keywords', HttpCode.INTERNAL_SERVER_ERROR);
throw new CustomError(
`Failed to get recommended keywords: ${err.message}`,
HttpCode.INTERNAL_SERVER_ERROR,
);
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/service/keywordCategory.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ async function createKeywordCategory(
logger.info(`Created new keyword category: ${JSON.stringify(newCategoryObj)}`);
return newCategoryObj;
} catch (err) {
logger.error(`Failed to create category ${info.name}: ${err.message}`);
throw new CustomError('Failed to create category', HttpCode.INTERNAL_SERVER_ERROR);
throw new CustomError(
`Failed to create category ${info.name}: ${err.message}`,
HttpCode.INTERNAL_SERVER_ERROR,
);
}
}

Expand Down Expand Up @@ -55,6 +57,7 @@ async function deleteKeywordCategory(categoryName: string): Promise<boolean> {
if (_.isNull(deletedCategory)) {
throw new CustomError(`Category with Name ${categoryName} not found`, HttpCode.NOT_FOUND);
}

return true;
}

Expand Down
28 changes: 11 additions & 17 deletions src/service/meme.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ async function getMeme(memeId: string): Promise<IMemeDocument | null> {

return meme || null;
} catch (err) {
logger.error(`Failed to get a meme(${memeId}): ${err.message}`);
throw new CustomError(`Failed to get a meme(${memeId})`, HttpCode.INTERNAL_SERVER_ERROR);
throw new CustomError(
`Failed to get a meme(${memeId}): ${err.message}`,
HttpCode.INTERNAL_SERVER_ERROR,
);
}
}

Expand Down Expand Up @@ -51,9 +53,8 @@ async function getMemeWithKeywords(
isReaction: !_.isNil(isReaction),
};
} catch (err) {
logger.error(`Failed to get a meme(${meme._id}) with keywords: ${err.message}`);
throw new CustomError(
`Failed to get a meme(${meme._id}) with keywords`,
`Failed to get a meme(${meme._id}) with keywords: ${err.message}`,
HttpCode.INTERNAL_SERVER_ERROR,
);
}
Expand All @@ -78,9 +79,8 @@ async function getTodayMemeList(

return memeList;
} catch (err) {
logger.error(`Failed to get today meme list: ${err.message}`);
throw new CustomError(
`Failed to get today meme list ${err.message}`,
`Failed to get today meme list: ${err.message}`,
HttpCode.INTERNAL_SERVER_ERROR,
);
}
Expand Down Expand Up @@ -141,9 +141,8 @@ async function getMemeListWithKeywordsAndisSavedAndisReaction(
}),
);
} catch (err) {
logger.error('Failed to get keywords and isSaved info from meme list', err.message);
throw new CustomError(
`Failed to get keywords and isSaved info from meme list ${err.message}`,
`Failed to get keywords and isSaved info from meme list: ${err.message}`,
HttpCode.INTERNAL_SERVER_ERROR,
);
}
Expand Down Expand Up @@ -231,9 +230,8 @@ async function searchMemeByKeyword(
data: memeList,
};
} catch (err) {
logger.error(`Failed to search meme list with keyword(${keyword})`, err.message);
throw new CustomError(
`Failed to search meme list with keyword(${keyword})`,
`Failed to search meme list with keyword(${keyword}): ${err.message}`,
HttpCode.INTERNAL_SERVER_ERROR,
);
}
Expand Down Expand Up @@ -269,10 +267,8 @@ async function createMemeInteraction(
}
return true;
} catch (err) {
logger.error(`Failed to create memeInteraction(${interactionType})`, err.message);

throw new CustomError(
`Failed to create memeInteraction(${interactionType}) (${err.message})`,
`Failed to create memeInteraction(${interactionType}): ${err.message}`,
HttpCode.INTERNAL_SERVER_ERROR,
);
}
Expand All @@ -283,9 +279,8 @@ async function deleteMemeSave(user: IUserDocument, meme: IMemeDocument): Promise
await MemeInteractionService.deleteMemeInteraction(user, meme, InteractionType.SAVE);
return true;
} catch (err) {
logger.error(`Failed to delete meme save`, err.message);
throw new CustomError(
`Failed to delete meme save(${err.message})`,
`Failed to delete meme save: ${err.message}`,
HttpCode.INTERNAL_SERVER_ERROR,
);
}
Expand All @@ -307,9 +302,8 @@ async function getTopReactionImage(keyword: IKeywordDocument): Promise<string> {
logger.info(`Get top reaction meme - keyword(${keyword.name}), meme(${topReactionMeme._id})`);
return topReactionMeme.image;
} catch (err) {
logger.error(`Failed get top reaction meme image`, err.message);
throw new CustomError(
`Failed get top reaction meme(${err.message})`,
`Failed get top reaction meme image: ${err.message}`,
HttpCode.INTERNAL_SERVER_ERROR,
);
}
Expand Down
23 changes: 7 additions & 16 deletions src/service/memeInteraction.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,9 @@ async function getMemeInteractionInfo(
});

return memeInteraction || null;
} catch (error) {
logger.error(`Failed to get a MemeInteraction Info(${meme._id} - ${interactionType})`, {
error,
});
} catch (err) {
throw new CustomError(
`Failed to get a MemeInteraction Info(${meme._id} - ${interactionType})`,
`Failed to get a MemeInteraction info(${meme._id} - ${interactionType}): ${err.message}`,
HttpCode.INTERNAL_SERVER_ERROR,
);
}
Expand All @@ -60,9 +57,8 @@ async function getMemeInteractionInfoWithCondition(
const memeInteraction = await MemeInteractionModel.findOne(condition);
return memeInteraction || null;
} catch (err) {
logger.error(`Failed to get a MemeInteraction Info(${meme._id} - ${interactionType})`);
throw new CustomError(
`Failed to get a MemeInteraction Info(${meme._id} - ${interactionType})`,
`Failed to get a MemeInteraction Info(${meme._id} - ${interactionType}): ${err.message}`,
HttpCode.INTERNAL_SERVER_ERROR,
);
}
Expand All @@ -80,9 +76,8 @@ async function getMemeInteractionCount(
});
return count;
} catch (err) {
logger.error(`Failed to count MemeInteraction(${interactionType})`);
throw new CustomError(
`Failed to count MemeInteraction(${interactionType}) (${err.message})`,
`Failed to count MemeInteraction(${interactionType}): ${err.message}`,
HttpCode.INTERNAL_SERVER_ERROR,
);
}
Expand All @@ -109,9 +104,8 @@ async function getMemeInteractionList(

return memeInteractionList;
} catch (err) {
logger.error(`Failed to count MemeInteraction(${interactionType})`);
throw new CustomError(
`Failed to count MemeInteraction(${interactionType}) (${err.message})`,
`Failed to count MemeInteraction(${interactionType}): ${err.message}`,
HttpCode.INTERNAL_SERVER_ERROR,
);
}
Expand All @@ -131,9 +125,8 @@ async function createMemeInteraction(
await newMemeInteraction.save();
return newMemeInteraction;
} catch (err) {
logger.error(`Failed to create a MemeInteraction(${meme._id} - ${interactionType})`);
throw new CustomError(
`Failed to create a MemeInteraction(${meme._id} - ${interactionType})`,
`Failed to create a MemeInteraction(${meme._id} - ${interactionType}): ${err.message}`,
HttpCode.INTERNAL_SERVER_ERROR,
);
}
Expand Down Expand Up @@ -175,7 +168,6 @@ async function updateMemeInteraction(
break;

default:
logger.error(`Unsupported interactionType(${interactionType})`);
throw new CustomError(
`Unsupported interactionType(${interactionType})`,
HttpCode.BAD_REQUEST,
Expand All @@ -198,9 +190,8 @@ async function deleteMemeInteraction(

return memeInteraction;
} catch (err) {
logger.error(`Failed to delete a MemeInteraction(${meme._id} - ${interactionType})`);
throw new CustomError(
`Failed to delete a MemeInteraction(${meme._id} - ${interactionType})`,
`Failed to delete a MemeInteraction(${meme._id} - ${interactionType}): ${err.message}`,
HttpCode.INTERNAL_SERVER_ERROR,
);
}
Expand Down
Loading