Skip to content

Commit

Permalink
fix 404 issue on /sentinel/tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
zchsh committed Sep 13, 2024
1 parent 136335a commit ff3658f
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/pages/[productSlug]/tutorials/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: MPL-2.0
*/

import { GetStaticPropsContext } from 'next'
import { GetStaticPropsContext, GetStaticPropsResult } from 'next'
import { LearnProductData, LearnProductSlug, ProductSlug } from 'types/products'
import {
getCloudTutorialsViewProps,
Expand All @@ -28,19 +28,28 @@ function generateProductTutorialHomePaths() {

export async function getStaticProps({
params,
}: GetStaticPropsContext<{ productSlug: LearnProductSlug }>): Promise<{
props: ProductTutorialsViewProps
}> {
}: GetStaticPropsContext<{ productSlug: LearnProductSlug }>): Promise<
GetStaticPropsResult<ProductTutorialsViewProps>
> {
const productData = cachedGetProductData(params.productSlug)

/**
* Note: `hcp` is a "product" in Dev Dot but not in Learn,
* so we have to treat it slightly differently.
*/
const props =
productData.slug == 'hcp'
? await getCloudTutorialsViewProps()
: await getProductTutorialsViewProps(productData as LearnProductData)
let props
try {
const props =
productData.slug == 'hcp'
? await getCloudTutorialsViewProps()
: await getProductTutorialsViewProps(productData as LearnProductData)
} catch (e) {
if (e.toString() === 'Error: 404 Not Found') {
return { notFound: true }
} else {
throw e
}
}

return props
}
Expand Down

0 comments on commit ff3658f

Please sign in to comment.