Skip to content

Commit

Permalink
🎉 전역적 에러 처리 추가 (#124)
Browse files Browse the repository at this point in the history
* 🎉 라우트 별 에러 처리

* 🎉 공통 에러 처리
  • Loading branch information
oaoong authored Nov 28, 2023
1 parent 63a536e commit 51b4b39
Show file tree
Hide file tree
Showing 19 changed files with 267 additions and 316 deletions.
70 changes: 0 additions & 70 deletions src/app/(root)/(routes)/(home)/error.tsx

This file was deleted.

62 changes: 0 additions & 62 deletions src/app/(root)/(routes)/cards/[cardId]/modify/error.tsx

This file was deleted.

31 changes: 0 additions & 31 deletions src/app/(root)/(routes)/cards/new/error.tsx

This file was deleted.

62 changes: 0 additions & 62 deletions src/app/(root)/(routes)/chatrooms/[chatRoomId]/error.tsx

This file was deleted.

32 changes: 22 additions & 10 deletions src/app/(root)/(routes)/chatrooms/[chatRoomId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React from 'react'
import PageTitle from '@/components/domain/page-title'
import ApiEndPoint from '@/config/apiEndPoint'
import errorCodes from '@/config/errorCodes'
import ErrorMessages from '@/config/errorMessages'
import { ForbiddenError } from '@/lib/errors'
import apiClient from '@/services/apiClient'
import { getServerCookie } from '@/utils/getServerCookie'
import ChatRoomTemplate from './components/ChatRoomTemplate'
Expand All @@ -26,15 +29,24 @@ const getInitialUser = async () => {
}

const getInitialChatRoom = async (chatRoomId: string) => {
const token = getServerCookie()
const res = await apiClient.get(
ApiEndPoint.getChatRoom(chatRoomId),
{},
{
Authorization: `${token}`,
},
)
return res.data.chatRoomInfo
try {
const token = getServerCookie()
const res = await apiClient.get(
ApiEndPoint.getChatRoom(chatRoomId),
{},
{
Authorization: `${token}`,
},
)
return res.data.chatRoomInfo
} catch (e: any) {
const log = await e.response.json()
if (log.code === errorCodes.forbidden.code) {
throw new ForbiddenError(new Response(ErrorMessages.Forbidden))
}

throw new Error(e)
}
}

const getCompleteRequestInfo = async (completeRequestId: number) => {
Expand Down Expand Up @@ -74,7 +86,7 @@ const ChatPage = async ({ params }: ChatPageProps) => {

return (
<main className="relative flex flex-col items-center w-full gap-10 h-page pb-chat_input">
<header className="w-full flex flex-row items-center px-4">
<header className="flex flex-row items-center w-full px-4">
<PageTitle title="채팅방" />
{!isCompleteRequested && (
<CompleteRequestButton
Expand Down
31 changes: 0 additions & 31 deletions src/app/(root)/(routes)/mypage/error.tsx

This file was deleted.

25 changes: 20 additions & 5 deletions src/app/(root)/(routes)/suggestions/[myCardId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
import MaxWidthWrapper from '@/components/domain/max-width-wrapper'
import PageTitle from '@/components/domain/page-title'
import ApiEndPoint from '@/config/apiEndPoint'
import ErrorMessages from '@/config/errorMessages'
import { ForbiddenError } from '@/lib/errors'
import apiClient from '@/services/apiClient'
import { getCardInfo } from '@/services/card/card'
import { CardDetail } from '@/types/card'
import { getServerCookie } from '@/utils/getServerCookie'
import MyCardDescriptionSection from './components/my-card-description-section'
import MySuggestionListContent from './components/my-suggestion-list-content'

async function getMyCardInfo(cardId: string) {
try {
const res = await getCardInfo(Number(cardId))
return res.data.cardInfo
} catch (e) {
console.log(e)
const token = getServerCookie()

const resCard = await getCardInfo(Number(cardId))
const resUser = await apiClient.get(
ApiEndPoint.getValidateUser(),
{},
{
Authorization: `${token}`,
},
)

if (resUser.data.userInfo.userId !== resCard.data.userInfo.userId) {
throw new ForbiddenError(new Response(ErrorMessages.Forbidden))
}

return resCard.data.cardInfo
}

const SuggestCheckListPage = async ({
Expand Down
12 changes: 0 additions & 12 deletions src/app/(root)/not-found.tsx

This file was deleted.

15 changes: 15 additions & 0 deletions src/app/error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use client'

import ErrorGateway from '@/components/domain/errors/ErrorGateway'

type ErrorPageProps = {
error: Error & { digest?: string }
reset: () => void
}

export default function GlobalError({
error,
reset,
}: Readonly<ErrorPageProps>) {
return <ErrorGateway error={error} reset={reset} />
}
18 changes: 0 additions & 18 deletions src/app/global-error.tsx

This file was deleted.

Loading

0 comments on commit 51b4b39

Please sign in to comment.