Skip to content

Commit

Permalink
fix: requestErrorHandler to fetchQuery calls
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Feb 4, 2024
1 parent 5499991 commit 8844c36
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/app/(app)/(page-detail)/[slug]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { attachUAAndRealIp } from '~/lib/attach-ua'
import { getOgUrl } from '~/lib/helper.server'
import { getSummaryFromMd } from '~/lib/markdown'
import { getQueryClient } from '~/lib/query-client.server'
import { requestErrorHandler } from '~/lib/request.server'
import { CurrentPageDataProvider } from '~/providers/page/CurrentPageDataProvider'
import { LayoutRightSideProvider } from '~/providers/shared/LayoutRightSideProvider'
import { queries } from '~/queries/definition'
Expand All @@ -24,9 +25,9 @@ import {

const getData = async (params: PageParams) => {
attachUAAndRealIp()
const data = await getQueryClient().fetchQuery(
queries.page.bySlug(params.slug),
)
const data = await getQueryClient()
.fetchQuery(queries.page.bySlug(params.slug))
.catch(requestErrorHandler)
return data
}

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { attachUAAndRealIp } from '~/lib/attach-ua'
import { getOgUrl } from '~/lib/helper.server'
import { getSummaryFromMd } from '~/lib/markdown'
import { getQueryClient } from '~/lib/query-client.server'
import { requestErrorHandler } from '~/lib/request.server'
import { CurrentPostDataProvider } from '~/providers/post/CurrentPostDataProvider'
import { LayoutRightSideProvider } from '~/providers/shared/LayoutRightSideProvider'
import { queries } from '~/queries/definition'
Expand All @@ -19,9 +20,9 @@ import PostPage from './pageImpl'
const getData = async (params: PageParams) => {
const { category, slug } = params
attachUAAndRealIp()
const data = await getQueryClient().fetchQuery(
queries.post.bySlug(category, slug),
)
const data = await getQueryClient()
.fetchQuery(queries.post.bySlug(category, slug))
.catch(requestErrorHandler)
return data
}
export const generateMetadata = async ({
Expand Down
5 changes: 4 additions & 1 deletion src/lib/request.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { notFound } from 'next/navigation'
import { RequestError } from '@mx-space/api-client'

export const requestErrorHandler = (error: Error | RequestError) => {
if (error instanceof RequestError && error.status === 404) {
if (
error instanceof RequestError &&
(error.status === 404 || error.raw?.response?.status === 404)
) {
return notFound()
}
throw error
Expand Down

0 comments on commit 8844c36

Please sign in to comment.