Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎉 전역적 에러 처리 추가 #124

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
}
oaoong marked this conversation as resolved.
Show resolved Hide resolved

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
oaoong marked this conversation as resolved.
Show resolved Hide resolved
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