Skip to content

Commit

Permalink
Reworking server-side errors.
Browse files Browse the repository at this point in the history
Signed-off-by: Benoit Cloutier <[email protected]>
  • Loading branch information
nibivi77 committed Oct 24, 2023
1 parent 4c7f35d commit 9191b2a
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 22 deletions.
2 changes: 1 addition & 1 deletion graphql/queries/my-dashboard.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
schPageV1ByPath(_path: "/content/dam/decd-endc/content-fragments/sch/pages/my-dashboard") {
schPageV1ByPath(_path: "/content/dam/decd-endc/content-fragments/sch/pages/my-dashboards") {
item {
_path
scPageNameEn
Expand Down
85 changes: 64 additions & 21 deletions pages/my-dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import MostReqTasks from './../components/MostReqTasks'
import React from 'react'
import throttle from 'lodash.throttle'
import { acronym } from '../lib/acronym'
import { ErrorPage } from '../components/ErrorPage'

export default function MyDashboard(props) {
/* istanbul ignore next */
Expand All @@ -36,6 +37,25 @@ export default function MyDashboard(props) {
}
}, [throttledOnClickEvent])

const errorCode =
props.content?.err ||
props.bannerContent?.err ||
props.popupContent?.err ||
props.popupContentNA?.err ||
props.authModals?.err
if (errorCode !== undefined) {
return (
<ErrorPage
lang={props.locale !== undefined ? props.locale : 'en'}
errType={errorCode}
isAuth={false}
homePageLink={
props.locale === 'en' ? '/en/my-dashboard' : '/fr/mon-tableau-de-bord'
}
accountPageLink="/"
/>
)
}
return (
<div id="myDashboardContent" data-testid="myDashboardContent-test">
<Heading id="my-dashboard-heading" title={props.content.heading} />
Expand Down Expand Up @@ -96,36 +116,32 @@ export async function getServerSideProps({ req, res, locale }) {

const content = await getMyDashboardContent().catch((error) => {
logger.error(error)
res.statusCode = 500
throw error
const errAEM = { err: '500' }
return errAEM
})
const bannerContent = await getBetaBannerContent().catch((error) => {
logger.error(error)
// res.statusCode = 500
throw error
const errAEM = { err: '500' }
return errAEM
})
const popupContent = await getBetaPopupExitContent().catch((error) => {
logger.error(error)
// res.statusCode = 500
throw error
const errAEM = { err: '500' }
return errAEM
})

/*
* Uncomment this block to make Banner Popup Content display "Page Not Available"
* Comment "getBetaPopupExitContent()" block of code above.
*/
const popupContentNA = await getBetaPopupNotAvailableContent().catch(
(error) => {
logger.error(error)
// res.statusCode = 500
throw error
const errAEM = { err: '500' }
return errAEM
}
)

const authModals = await getAuthModalsContent().catch((error) => {
logger.error(error)
// res.statusCode = 500
throw error
const errAEM = { err: '500' }
return errAEM
})

if (locale === 'und') {
Expand Down Expand Up @@ -161,18 +177,45 @@ export async function getServerSideProps({ req, res, locale }) {
props: {
locale,
langToggleLink,
content: locale === 'en' ? content.en : content.fr,
content:
content?.err !== undefined
? content
: locale === 'en'
? content.en
: content.fr,
meta,
bannerContent: locale === 'en' ? bannerContent.en : bannerContent.fr,
popupContent: locale === 'en' ? popupContent.en : popupContent.fr,
popupContentNA: locale === 'en' ? popupContentNA.en : popupContentNA.fr,
aaPrefix: `ESDC-EDSC:${content.en?.heading || content.en?.title}`,
bannerContent:
bannerContent?.err !== undefined
? bannerContent
: locale === 'en'
? bannerContent.en
: bannerContent.fr,
popupContent:
popupContent?.err !== undefined
? popupContent
: locale === 'en'
? popupContent.en
: popupContent.fr,
popupContentNA:
popupContentNA?.err !== undefined
? popupContentNA
: locale === 'en'
? popupContentNA.en
: popupContentNA.fr,
aaPrefix:
content?.err !== undefined
? ''
: `ESDC-EDSC:${content.en?.heading || content.en?.title}`,
popupStaySignedIn:
locale === 'en'
authModals?.err !== undefined
? authModals
: locale === 'en'
? authModals.mappedPopupStaySignedIn.en
: authModals.mappedPopupStaySignedIn.fr,
popupYouHaveBeenSignedout:
locale === 'en'
authModals?.err !== undefined
? authModals
: locale === 'en'
? authModals.mappedPopupSignedOut.en
: authModals.mappedPopupSignedOut.fr,
},
Expand Down

0 comments on commit 9191b2a

Please sign in to comment.