Skip to content

Commit 9922ce3

Browse files
Merge pull request #85 from abhitrueprogrammer/staging
BugFix, Enchancement: Better errors in paper-by-id and fixed schema
2 parents 7477f52 + c08f029 commit 9922ce3

File tree

3 files changed

+109
-103
lines changed

3 files changed

+109
-103
lines changed

src/app/api/paper-by-id/[id]/route.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ export async function GET(req: Request, { params }: { params: { id: string } })
1414
}
1515

1616
const paper = await Paper.findById(id);
17-
17+
18+
1819
if (!paper) {
1920
return NextResponse.json({ message: "Paper not found" }, { status: 404 });
2021
}

src/app/paper/[id]/page.tsx

Lines changed: 107 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -13,111 +13,117 @@ export async function generateMetadata({
1313
}: {
1414
params: { id: string };
1515
}): Promise<Metadata> {
16-
const paper: PaperResponse | null = await fetchPaperID(params.id);
16+
try {
17+
const paper: PaperResponse | null = await fetchPaperID(params.id);
1718

18-
if (paper) {
19-
return {
20-
metadataBase: new URL("https://papers.codechefvit.com/"),
21-
title: `Papers | ${paper.subject} | ${paper.exam} | ${paper.slot}`,
22-
description: `Discover ${paper.subject}'s question paper created by CodeChef-VIT at Vellore Institute of Technology. Made with ♡ to help students excel.`,
23-
icons: [{ rel: "icon", url: "/codechef_logo.svg" }],
24-
openGraph: {
25-
title: `Papers | ${paper.subject} | ${paper.exam} | ${paper.slot}`,
26-
images: [{ url: "/papers.png" }],
27-
url: "https://papers.codechefvit.com/",
28-
type: "website",
29-
description: `Discover ${paper.subject}'s question paper created by CodeChef-VIT at Vellore Institute of Technology. Made with ♡ to help students excel.`,
30-
siteName: "Papers by CodeChef-VIT",
31-
},
32-
twitter: {
33-
card: "summary_large_image",
19+
if (paper) {
20+
return {
21+
metadataBase: new URL("https://papers.codechefvit.com/"),
3422
title: `Papers | ${paper.subject} | ${paper.exam} | ${paper.slot}`,
3523
description: `Discover ${paper.subject}'s question paper created by CodeChef-VIT at Vellore Institute of Technology. Made with ♡ to help students excel.`,
36-
images: [{ url: "/papers.png" }],
37-
},
38-
applicationName: "Papers by CodeChef-VIT",
39-
keywords: [
40-
"CodeChef",
41-
"VIT",
42-
"Vellore Institute of Technology",
43-
"CodeChef-VIT",
44-
"Papers",
45-
"Exam solutions",
46-
"Student resources",
47-
"VIT exam papers",
48-
"Exam preparation",
49-
"Previous year papers VIT",
50-
"VITCAT1",
51-
"VITCAT2",
52-
"VITFAT",
53-
"VIT CAT1 papers",
54-
"VIT CAT2 papers",
55-
"VIT FAT papers",
56-
"VIT exam question papers",
57-
"VIT question bank",
58-
"VIT previous year question papers",
59-
"VIT academic resources",
60-
"VIT exam pattern",
61-
"VIT preparation tips",
62-
"VIT question solutions",
63-
"VIT model papers",
64-
"VIT solved papers",
65-
"VIT test papers",
66-
"VIT sample papers",
67-
"VIT question papers with solutions",
68-
"VIT exam guide",
69-
"VIT CAT1 preparation",
70-
"VIT CAT2 preparation",
71-
"VIT FAT preparation",
72-
"VIT previous year CAT1 papers",
73-
"VIT previous year CAT2 papers",
74-
"VIT previous year FAT papers",
75-
"VIT exam resources",
76-
"VIT academic help",
77-
"VIT syllabus",
78-
"VIT question paper pattern",
79-
"VIT 2023 papers",
80-
"VIT 2024 papers",
81-
"VIT exam practice",
82-
"VIT question paper archives",
83-
"VIT study materials",
84-
"VIT engineering papers",
85-
"VIT exam strategy",
86-
"VIT online exam resources",
87-
"VIT question paper download",
88-
"VIT important questions",
89-
"VIT question paper solutions",
90-
`${paper.subject} question paper`,
91-
`${paper.exam} question paper`,
92-
`${paper.slot} question paper`,
93-
`${paper.year} question paper`,
94-
`${paper.subject} question paper`,
95-
`${paper.exam} question paper`,
96-
`${paper.slot} question paper`,
97-
`${paper.year} question paper`,
98-
`${paper.subject} ${paper.exam} question paper`,
99-
`${paper.subject} ${paper.slot} question paper`,
100-
`${paper.subject} ${paper.year} question paper`,
101-
`${paper.exam} ${paper.slot} question paper`,
102-
`${paper.exam} ${paper.year} question paper`,
103-
`${paper.subject} ${paper.exam} ${paper.year} question paper`,
104-
`${paper.subject} ${paper.exam} ${paper.slot} question paper`,
105-
`${paper.subject} ${paper.year} ${paper.slot} question paper`,
106-
`${paper.exam} ${paper.year} ${paper.slot} question paper`,
107-
`${paper.subject} ${paper.exam} ${paper.year} ${paper.slot} question paper`,
108-
`${paper.year} ${paper.subject} ${paper.slot} question paper`,
109-
`${paper.year} ${paper.exam} ${paper.subject} question paper`,
110-
`${paper.exam} ${paper.subject} ${paper.year} question paper`,
111-
`${paper.slot} ${paper.subject} ${paper.year} question paper`,
112-
`${paper.slot} ${paper.exam} ${paper.year} question paper`,
113-
],
114-
robots: "index, follow",
24+
icons: [{ rel: "icon", url: "/codechef_logo.svg" }],
25+
openGraph: {
26+
title: `Papers | ${paper.subject} | ${paper.exam} | ${paper.slot}`,
27+
images: [{ url: "/papers.png" }],
28+
url: "https://papers.codechefvit.com/",
29+
type: "website",
30+
description: `Discover ${paper.subject}'s question paper created by CodeChef-VIT at Vellore Institute of Technology. Made with ♡ to help students excel.`,
31+
siteName: "Papers by CodeChef-VIT",
32+
},
33+
twitter: {
34+
card: "summary_large_image",
35+
title: `Papers | ${paper.subject} | ${paper.exam} | ${paper.slot}`,
36+
description: `Discover ${paper.subject}'s question paper created by CodeChef-VIT at Vellore Institute of Technology. Made with ♡ to help students excel.`,
37+
images: [{ url: "/papers.png" }],
38+
},
39+
applicationName: "Papers by CodeChef-VIT",
40+
keywords: [
41+
"CodeChef",
42+
"VIT",
43+
"Vellore Institute of Technology",
44+
"CodeChef-VIT",
45+
"Papers",
46+
"Exam solutions",
47+
"Student resources",
48+
"VIT exam papers",
49+
"Exam preparation",
50+
"Previous year papers VIT",
51+
"VITCAT1",
52+
"VITCAT2",
53+
"VITFAT",
54+
"VIT CAT1 papers",
55+
"VIT CAT2 papers",
56+
"VIT FAT papers",
57+
"VIT exam question papers",
58+
"VIT question bank",
59+
"VIT previous year question papers",
60+
"VIT academic resources",
61+
"VIT exam pattern",
62+
"VIT preparation tips",
63+
"VIT question solutions",
64+
"VIT model papers",
65+
"VIT solved papers",
66+
"VIT test papers",
67+
"VIT sample papers",
68+
"VIT question papers with solutions",
69+
"VIT exam guide",
70+
"VIT CAT1 preparation",
71+
"VIT CAT2 preparation",
72+
"VIT FAT preparation",
73+
"VIT previous year CAT1 papers",
74+
"VIT previous year CAT2 papers",
75+
"VIT previous year FAT papers",
76+
"VIT exam resources",
77+
"VIT academic help",
78+
"VIT syllabus",
79+
"VIT question paper pattern",
80+
"VIT 2023 papers",
81+
"VIT 2024 papers",
82+
"VIT exam practice",
83+
"VIT question paper archives",
84+
"VIT study materials",
85+
"VIT engineering papers",
86+
"VIT exam strategy",
87+
"VIT online exam resources",
88+
"VIT question paper download",
89+
"VIT important questions",
90+
"VIT question paper solutions",
91+
`${paper.subject} question paper`,
92+
`${paper.exam} question paper`,
93+
`${paper.slot} question paper`,
94+
`${paper.year} question paper`,
95+
`${paper.subject} question paper`,
96+
`${paper.exam} question paper`,
97+
`${paper.slot} question paper`,
98+
`${paper.year} question paper`,
99+
`${paper.subject} ${paper.exam} question paper`,
100+
`${paper.subject} ${paper.slot} question paper`,
101+
`${paper.subject} ${paper.year} question paper`,
102+
`${paper.exam} ${paper.slot} question paper`,
103+
`${paper.exam} ${paper.year} question paper`,
104+
`${paper.subject} ${paper.exam} ${paper.year} question paper`,
105+
`${paper.subject} ${paper.exam} ${paper.slot} question paper`,
106+
`${paper.subject} ${paper.year} ${paper.slot} question paper`,
107+
`${paper.exam} ${paper.year} ${paper.slot} question paper`,
108+
`${paper.subject} ${paper.exam} ${paper.year} ${paper.slot} question paper`,
109+
`${paper.year} ${paper.subject} ${paper.slot} question paper`,
110+
`${paper.year} ${paper.exam} ${paper.subject} question paper`,
111+
`${paper.exam} ${paper.subject} ${paper.year} question paper`,
112+
`${paper.slot} ${paper.subject} ${paper.year} question paper`,
113+
`${paper.slot} ${paper.exam} ${paper.year} question paper`,
114+
],
115+
robots: "index, follow",
116+
};
117+
}
118+
119+
return {
120+
title: "Paper not found",
121+
};
122+
} catch {
123+
return {
124+
title: "Paper not found",
115125
};
116126
}
117-
118-
return {
119-
title: "Paper not found",
120-
};
121127
}
122128
const PaperPage = async ({ params }: { params: { id: string } }) => {
123129
async function getPaper() {
@@ -133,7 +139,7 @@ const PaperPage = async ({ params }: { params: { id: string } }) => {
133139
return errorResponse?.data?.message ?? "Failed to fetch paper";
134140
}
135141
} else {
136-
return "An unknown error occurred";
142+
return `${err}`;
137143
}
138144
}
139145
}

src/db/papers.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const adminSchema = new Schema<IAdminPaper>({
1515
isSelected: { type: Boolean, default: false },
1616
});
1717
const paperSchema = new Schema<IPaper>({
18-
_id: { type: String, required: true },
1918
finalUrl: { type: String, required: true },
2019
thumbnailUrl: { type: String, required: true },
2120
subject: { type: String, required: true, index: true },

0 commit comments

Comments
 (0)