Skip to content

Commit

Permalink
Feat: 에러처리 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
yoouyeon committed Jun 30, 2024
1 parent 3a1509d commit eb0a751
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/app/job/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
'use client'

import useAxiosWithAuth from '@/api/config'
import CuCircularProgress from '@/components/CuCircularProgress'
import HitsCounter from '@/components/HitsCounter'
import {
DetailContent,
DetailContentCotainer,
DetailPage,
} from '@/components/board/DetailPanel'
import useToast from '@/states/useToast'
import UTCtoLocalTime from '@/utils/UTCtoLocalTime'
import { useRouter } from 'next/navigation'
import { useEffect } from 'react'
import useSWR from 'swr'

export interface IJobDetail {
Expand All @@ -26,9 +29,19 @@ const JobDetailPage = ({ params }: { params: { id: string } }) => {
`/api/v1/job/${params.id}`,
async (url: string) => axiosWithAuth.get(url).then((res) => res.data),
)
const { openToast } = useToast()
useEffect(() => {
if (!data && !isLoading) {
openToast({
severity: 'error',
message: '게시글을 불러오는 데 실패했습니다.',
})
router.push('/job')
}
}, [data, isLoading, openToast, router])

if (isLoading) return <div>Loading...</div>
if (!data) return <div>데이터가 없습니다.</div>
if (isLoading) return <CuCircularProgress color="primary" />
if (!data) return null

return (
<DetailPage
Expand Down

0 comments on commit eb0a751

Please sign in to comment.