Skip to content

Commit 9da65fd

Browse files
authored
Merge pull request #372 from Quickchive/develop
Develop to master
2 parents 9826f98 + d31e56a commit 9da65fd

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

src/contents/contents.service.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,22 @@ export class ContentsService {
6666

6767
categoryId = categoryId ? categoryId : parentId;
6868

69-
const {
70-
title: linkTitle,
71-
siteName,
72-
description,
73-
coverImg,
74-
} = await getLinkInfo(link);
75-
title = title ? title : linkTitle;
69+
let siteName: string | undefined;
70+
let description: string | undefined;
71+
let coverImg: string | undefined;
72+
73+
try {
74+
const {
75+
title: linkTitle,
76+
siteName: _siteName,
77+
description: _description,
78+
coverImg: _coverImg,
79+
} = await getLinkInfo(link);
80+
title = title ? title : linkTitle;
81+
siteName = _siteName;
82+
description = _description;
83+
coverImg = _coverImg;
84+
} catch (e) {}
7685

7786
const content = new Content();
7887

@@ -366,11 +375,11 @@ export class ContentsService {
366375
);
367376

368377
// 크롤링 후 처리
369-
let summary: string = '';
378+
let summary = '';
370379
if (!document) {
371380
throw new BadRequestException('Document not found.');
372381
} else if (document.length > 1900) {
373-
let sliceIndex: number = 0;
382+
let sliceIndex = 0;
374383
for (let i = 0; i < Math.ceil(document.length / 1900); i++) {
375384
const slicedSummary = await this.summaryService.summaryContent({
376385
title: content?.title,
@@ -403,10 +412,10 @@ export class ContentsService {
403412
content: document,
404413
}: SummarizeContentBodyDto): Promise<SummarizeContentOutput> {
405414
try {
406-
let summary: string = '';
415+
let summary = '';
407416

408417
if (document.length > 1900) {
409-
let sliceIndex: number = 0;
418+
let sliceIndex = 0;
410419
for (let i = 0; i < Math.ceil(document.length / 1900); i++) {
411420
const slicedSummary = await this.summaryService.summaryContent({
412421
title,

src/contents/util/content.util.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,16 @@ class OGCrawler {
7272

7373
return this.parse(response.data);
7474
} catch (error) {
75-
if (error instanceof AxiosError && error.response?.status === 403) {
76-
throw new ForbiddenException('og 데이터를 가져올 수 없는 링크입니다.');
75+
if (error instanceof AxiosError) {
76+
if (
77+
error?.response?.status === 400 ||
78+
error.response?.status === 403 ||
79+
error.response?.status === 404
80+
) {
81+
throw new ForbiddenException(
82+
'og 데이터를 가져올 수 없는 링크입니다.',
83+
);
84+
}
7785
}
7886

7987
throw new InternalServerErrorException('An unknown error occurred');

0 commit comments

Comments
 (0)