Skip to content

Commit

Permalink
fix: add exception handling to rendering (#319)
Browse files Browse the repository at this point in the history
* fix: add exception handling to rendering

* fix: render 500 on error

* chore: remove redundant comments

* chore: remove redundant comments

* chore: remove notFound

* chore: remove isError

* feat(home): integrate photostory and witsdom (#340)

* feat(home): integrate photostory and witsdom

* style(home): banner of photostory and witsdom

* fix: add exception handling to rendering

* fix: add meta data for 500 page, and user portfolio page

* chore: prettier check

Co-authored-by: G.Anish Kumar Patro <105335549+anish-patro@users.noreply.github.com>
  • Loading branch information
Shurtu-gal and anish-patro authored Dec 11, 2022
1 parent 74a40c0 commit 728fe76
Show file tree
Hide file tree
Showing 8 changed files with 1,043 additions and 341 deletions.
165 changes: 121 additions & 44 deletions client/src/pages/[category]/[...subCategory].jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ import ROUTES from '../../utils/getRoutes';
// Graphql
import getArticlesByCategories from '../../graphql/queries/category/getArticlesByCategories';
import countOfArticlesBySubCategory from '../../graphql/queries/subcategory/countOfArticlesBySubCategory';
import Custom500 from '../500';

const CategoryPage = ({
categoryName,
subCategoryDetails,
articleList,
countOfArticles,
pageNumber,
isError,
}) => {
const { isFallback, push } = useRouter();

Expand Down Expand Up @@ -49,6 +51,73 @@ const CategoryPage = ({
setPageNo(value);
};

if (isError) {
return (
<>
<Head>
{/* <!-- =============== Primary Meta Tags =============== --> */}
<title> Monday Morning </title>
<meta name='title' content={`Monday Morning`} />
<meta
name='description'
content='Monday Morning is the official Student Media Body of National Institute Of Technology Rourkela. Monday Morning covers all the events, issues and activities going on inside the campus. Monday Morning also serves as a link between the administration and the students.'
/>
<meta
name='keywords'
content={`monday morning, mondaymorning, monday morning, mm, nit rkl, nit, nit rourkela, nitr, nitrkl, rkl, rourkela`}
/>

{/* <!-- =============== Open Graph / Facebook =============== --> */}
<meta property='og:type' content='website' />
<meta
property='og:url'
content={`https://mondaymorning.nitrkl.ac.in/`}
/>
<meta
property='og:site_name'
content='Monday Morning | The Student Media Body of NIT Rourkela, India'
/>
<meta property='og:title' content={`Monday Morning`} />
<meta
property='og:description'
content='Monday Morning is the Media Body of National Institute Of Technology Rourkela. Monday Morning covers all the events, issues and activities going on inside the campus. Monday morning also serves as a link between the administration and the students.'
/>
<meta
property='og:image'
itemProp='image'
content='/icon-256x256.png'
/>
<meta
property='og:image:url'
content='https://mondaymorning.nitrkl.ac.in/icon-256x256.png'
/>
<meta
property='og:image:secure_url'
content='https://mondaymorning.nitrkl.ac.in/icon-256x256.png'
/>
<meta property='og:image:type' content='image/png' />

{/* <!-- =============== Twitter =============== --> */}
<meta property='twitter:card' content='summary_large_image' />
<meta
property='twitter:url'
content={`https://mondaymorning.nitrkl.ac.in`}
/>
<meta property='twitter:title' content='Monday Morning' />
<meta
property='twitter:image'
content='https://mondaymorning.nitrkl.ac.in/icon-256x256.png'
/>
<meta
property='twitter:description'
content='Monday Morning is the Media Body of National Institute Of Technology Rourkela. Monday Morning covers all the events, issues and activities going on inside the campus. Monday morning also serves as a link between the administration and the students.'
/>
</Head>
<Custom500 />
</>
);
}

return (
<>
<Head>
Expand Down Expand Up @@ -141,55 +210,63 @@ export async function getStaticProps({
},
preview,
}) {
const categoryName = ROUTES.CATEGORIES.filter(
({ asyncRoutePath }) => asyncRoutePath === './Category',
).filter(({ shortName }) => shortName === category)[0]?.shortName;
try {
const categoryName = ROUTES.CATEGORIES.filter(
({ asyncRoutePath }) => asyncRoutePath === './Category',
).filter(({ shortName }) => shortName === category)[0]?.shortName;

const subCategoryDetails = ROUTES.SUB_CATEGORIES.OBJECT[
categoryName?.toUpperCase()
]
?.filter(({ asyncRoutePath }) => asyncRoutePath === './SubCategory')
.filter(({ shortName }) => shortName === subCategory)[0];
const subCategoryDetails = ROUTES.SUB_CATEGORIES.OBJECT[
categoryName?.toUpperCase()
]
?.filter(({ asyncRoutePath }) => asyncRoutePath === './SubCategory')
.filter(({ shortName }) => shortName === subCategory)[0];

if (!subCategoryDetails) {
return {
notFound: true,
};
}

const {
data: { getArticlesByCategories: articleList },
} = await GraphClient.query({
query: getArticlesByCategories,
variables: {
categoryNumbers: [subCategoryDetails?.idNumber],
limit: 7,
offset: 7 * (parseInt(pageNumber) - 1),
},
});

const {
data: { countOfArticlesBySubCategory: countOfArticles },
} = await GraphClient.query({
query: countOfArticlesBySubCategory,
variables: {
categoryNumber: subCategoryDetails?.idNumber,
},
});

if (!subCategoryDetails) {
return {
notFound: true,
props: {
categoryName,
subCategoryDetails,
articleList,
countOfArticles,
pageNumber: parseInt(pageNumber),
},
revalidate:
preview || new Date(Date.now()).getDay() < 3
? 60 * 60 * 1
: 60 * 60 * 24 * 2, // 1 Hour or 2 Days
};
} catch (err) {
return {
props: {
isError: true,
},
};
}

const {
data: { getArticlesByCategories: articleList },
} = await GraphClient.query({
query: getArticlesByCategories,
variables: {
categoryNumbers: [subCategoryDetails?.idNumber],
limit: 7,
offset: 7 * (parseInt(pageNumber) - 1),
},
});

const {
data: { countOfArticlesBySubCategory: countOfArticles },
} = await GraphClient.query({
query: countOfArticlesBySubCategory,
variables: {
categoryNumber: subCategoryDetails?.idNumber,
},
});

return {
props: {
categoryName,
subCategoryDetails,
articleList,
countOfArticles,
pageNumber: parseInt(pageNumber),
},
revalidate:
preview || new Date(Date.now()).getDay() < 3
? 60 * 60 * 1
: 60 * 60 * 24 * 2, // 1 Hour or 2 Days
};
}

export async function getStaticPaths() {
Expand Down
159 changes: 124 additions & 35 deletions client/src/pages/[category]/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,83 @@ import ROUTES from '../../utils/getRoutes';

// Graphql
import getArticlesByCategories from '../../graphql/queries/category/getArticlesByCategories';
import Custom500 from '../500';

const CategoryPage = ({ articleList, categoryShortName, category }) => {
const CategoryPage = ({
articleList,
categoryShortName,
category,
isError,
}) => {
const { isFallback } = useRouter();

if (isError) {
return (
<>
<Head>
{/* <!-- =============== Primary Meta Tags =============== --> */}
<title> Monday Morning </title>
<meta name='title' content={`Monday Morning`} />
<meta
name='description'
content='Monday Morning is the official Student Media Body of National Institute Of Technology Rourkela. Monday Morning covers all the events, issues and activities going on inside the campus. Monday Morning also serves as a link between the administration and the students.'
/>
<meta
name='keywords'
content={`monday morning, mondaymorning, monday morning, mm, nit rkl, nit, nit rourkela, nitr, nitrkl, rkl, rourkela`}
/>

{/* <!-- =============== Open Graph / Facebook =============== --> */}
<meta property='og:type' content='website' />
<meta
property='og:url'
content={`https://mondaymorning.nitrkl.ac.in/`}
/>
<meta
property='og:site_name'
content='Monday Morning | The Student Media Body of NIT Rourkela, India'
/>
<meta property='og:title' content={`Monday Morning`} />
<meta
property='og:description'
content='Monday Morning is the Media Body of National Institute Of Technology Rourkela. Monday Morning covers all the events, issues and activities going on inside the campus. Monday morning also serves as a link between the administration and the students.'
/>
<meta
property='og:image'
itemProp='image'
content='/icon-256x256.png'
/>
<meta
property='og:image:url'
content='https://mondaymorning.nitrkl.ac.in/icon-256x256.png'
/>
<meta
property='og:image:secure_url'
content='https://mondaymorning.nitrkl.ac.in/icon-256x256.png'
/>
<meta property='og:image:type' content='image/png' />

{/* <!-- =============== Twitter =============== --> */}
<meta property='twitter:card' content='summary_large_image' />
<meta
property='twitter:url'
content={`https://mondaymorning.nitrkl.ac.in`}
/>
<meta property='twitter:title' content='Monday Morning' />
<meta
property='twitter:image'
content='https://mondaymorning.nitrkl.ac.in/icon-256x256.png'
/>
<meta
property='twitter:description'
content='Monday Morning is the Media Body of National Institute Of Technology Rourkela. Monday Morning covers all the events, issues and activities going on inside the campus. Monday morning also serves as a link between the administration and the students.'
/>
</Head>
<Custom500 />
</>
);
}

return (
<>
<Head>
Expand Down Expand Up @@ -100,47 +174,62 @@ export async function getStaticProps({
params: { category: categoryShortName },
preview,
}) {
const category = ROUTES.CATEGORIES.filter(
({ asyncRoutePath }) => asyncRoutePath === './Category',
).filter(({ shortName }) => shortName === categoryShortName)[0];

const {
data: { getArticlesByCategories: articleList },
} = await GraphClient.query({
query: getArticlesByCategories,
variables: {
categoryNumbers: [category?.idNumber, ...category?.subCategoryIds],
limit: 4,
},
});

if (!category || !articleList) {
try {
const category = ROUTES.CATEGORIES.filter(
({ asyncRoutePath }) => asyncRoutePath === './Category',
).filter(({ shortName }) => shortName === categoryShortName)[0];

const {
data: { getArticlesByCategories: articleList },
} = await GraphClient.query({
query: getArticlesByCategories,
variables: {
categoryNumbers: [category?.idNumber, ...category?.subCategoryIds],
limit: 4,
},
});

if (!category || !articleList) {
return {
notFound: true,
};
}

return {
notFound: true,
props: {
articleList,
categoryShortName,
category,
},
revalidate:
preview || new Date(Date.now()).getDay() < 3
? 60 * 60 * 1
: 60 * 60 * 24 * 2, // 1 Hour or 2 Days
};
} catch (err) {
return {
props: {
isError: true,
},
};
}

return {
props: {
articleList,
categoryShortName,
category,
},
revalidate:
preview || new Date(Date.now()).getDay() < 3
? 60 * 60 * 1
: 60 * 60 * 24 * 2, // 1 Hour or 2 Days
};
}

export async function getStaticPaths() {
const paths = ROUTES.CATEGORIES.filter(
({ asyncRoutePath }) => asyncRoutePath === './Category',
).map(({ shortName }) => ({
params: { category: shortName },
}));
try {
const paths = ROUTES.CATEGORIES.filter(
({ asyncRoutePath }) => asyncRoutePath === './Category',
).map(({ shortName }) => ({
params: { category: shortName },
}));

return { paths, fallback: false };
return { paths, fallback: false };
} catch (e) {
return {
paths: { params: { subCategory: ['error', 'error'] } },
fallback: true,
};
}
}

export default CategoryPage;
Loading

0 comments on commit 728fe76

Please sign in to comment.