Skip to content

Commit

Permalink
Add individual status error pages
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvinkipruto committed Sep 20, 2023
1 parent 612a0f7 commit 6d0153f
Showing 1 changed file with 75 additions and 4 deletions.
79 changes: 75 additions & 4 deletions apps/codeforafrica/src/lib/data/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,62 @@ function getPageSlug({ params }) {
return params?.slugs?.[pageSlugIndex] || "index";
}

function getDefaultErrorPageProps() {
function getDefaultErrorPageProps(statusCode = 404) {
if (statusCode === 500) {
return {
title: "Server Error. ",
subtitle: [
{
children: [
{
text: "Don't worry!, you can head back to our ",
children: null,
},
{
type: "link",
newTab: false,
url: "/",
children: [
{
text: "homepage",
children: null,
},
],
href: "/",
},
{
text: "check out our most recent ",
children: null,
},
{
type: "link",
newTab: false,
url: "/projects",
children: [
{
text: "projects",
children: null,
},
],
href: "/projects",
},
{
text: ", or read below some of the contents produced by our amazing team while the technical team is working on fixing the issue.",
children: null,
},
],
},
],
};
}

return {
title: "Page not found. ",
title: "Whoops! This page got lost in conversation! ",
subtitle: [
{
children: [
{
text: "Visit our ",
text: "Don't worry!, you can head back to our ",
children: null,
},
{
Expand All @@ -66,6 +114,26 @@ function getDefaultErrorPageProps() {
],
href: "/",
},
{
text: "check out our most recent ",
children: null,
},
{
type: "link",
newTab: false,
url: "/projects",
children: [
{
text: "projects",
children: null,
},
],
href: "/projects",
},
{
text: ", or read below some of the contents produced by our amazing team.",
children: null,
},
],
},
],
Expand All @@ -77,7 +145,10 @@ export async function getPageProps(api, context) {
const {
docs: [page],
} = await api.findPage(slug);
if (!page && (slug === "404" || slug === "500")) {
if (!page) {
if (slug === "500") {
return getDefaultErrorPageProps(500);
}
return getDefaultErrorPageProps();
}
if (!page) {
Expand Down

0 comments on commit 6d0153f

Please sign in to comment.