Skip to content

Commit

Permalink
Merge branch 'GDSC-Hongik:dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
GDSChongik authored Aug 22, 2024
2 parents 8d862b4 + 3116d07 commit c59ec53
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 11 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
"nanoid": "^5.0.7",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-error-boundary": "^4.0.13",
"react-hook-form": "^7.50.1",
"react-router-dom": "^6.22.1",
"react-toastify": "^10.0.4",
"wowds-icons": "^0.1.0",
"wowds-tokens": "^0.0.9",
"zustand": "^4.5.0",
"wowds-ui": "^0.1.9"
"wowds-ui": "^0.1.9",
"zustand": "^4.5.0"
},
"devDependencies": {
"@sentry/react": "^8.22.0",
Expand Down
12 changes: 12 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added public/notfound.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 24 additions & 5 deletions src/components/ApiErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { PropsWithChildren } from 'react';

import * as Sentry from '@sentry/react';
import { useQueryClient } from '@tanstack/react-query';
import { AxiosError } from 'axios';
import { redirect } from 'react-router-dom';
import { toast } from 'react-toastify';
import RoutePath from '@/routes/routePath';
import { ReactNode } from 'react';

type ErrorResponseType = {
errorCodeName: string;
errorMessage: string;
};

export default function ApiErrorBoundary({ children }: PropsWithChildren) {
export default function ApiErrorBoundary({
children
}: {
children: ReactNode;
}) {
const queryClient = useQueryClient();

queryClient.getQueryCache().config = {
Expand All @@ -24,7 +28,10 @@ export default function ApiErrorBoundary({ children }: PropsWithChildren) {

function handleError(axiosError: AxiosError) {
const errorResponse = axiosError.response?.data as ErrorResponseType;

if (errorResponse) {
// eslint-disable-next-line import/namespace
Sentry.captureException(errorResponse, {});
}
const message = errorResponse.errorMessage;

switch (axiosError.response?.status) {
Expand All @@ -38,7 +45,19 @@ export default function ApiErrorBoundary({ children }: PropsWithChildren) {
toast.error(message);
break;
}

if (errorResponse) {
// eslint-disable-next-line import/namespace
Sentry.captureException(errorResponse, {});
}
}

return <>{children}</>;
return (
<ErrorBoundary

Check failure on line 56 in src/components/ApiErrorBoundary.tsx

View workflow job for this annotation

GitHub Actions / build

Cannot find name 'ErrorBoundary'. Did you mean 'ApiErrorBoundary'?
{...rest}

Check failure on line 57 in src/components/ApiErrorBoundary.tsx

View workflow job for this annotation

GitHub Actions / build

Cannot find name 'rest'.
onError={(error) => handleError(error as AxiosError)}

Check failure on line 58 in src/components/ApiErrorBoundary.tsx

View workflow job for this annotation

GitHub Actions / build

Parameter 'error' implicitly has an 'any' type.
fallbackRender={() => <NotFoundPage />}>

Check failure on line 59 in src/components/ApiErrorBoundary.tsx

View workflow job for this annotation

GitHub Actions / build

Cannot find name 'NotFoundPage'.
{children}
</ErrorBoundary>

Check failure on line 61 in src/components/ApiErrorBoundary.tsx

View workflow job for this annotation

GitHub Actions / build

Cannot find name 'ErrorBoundary'. Did you mean 'ApiErrorBoundary'?
);
}
15 changes: 15 additions & 0 deletions src/components/common/AsyncBoundary.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ErrorBoundary } from '@sentry/react';
import { Suspense, SuspenseProps } from 'react';
import LoadingSpinner from './LoadingSpinner';

type AsyncBoundaryProps = Omit<SuspenseProps, 'fallback'>;

const AsyncBoundary = ({ children, ...rest }: AsyncBoundaryProps) => {
return (
<ErrorBoundary {...rest}>
<Suspense fallback={<LoadingSpinner />}>{children}</Suspense>
</ErrorBoundary>
);
};

export default AsyncBoundary;
73 changes: 73 additions & 0 deletions src/pages/NotFound.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { Flex, Space, Text } from '@/components/common/Wrapper';
import * as Sentry from '@sentry/react';
import GlobalSize from '@/constants/globalSize';
import { media } from '@/styles';
import styled from '@emotion/styled';
import { useNavigate } from 'react-router-dom';
import { color } from 'wowds-tokens';
import Button from 'wowds-ui/Button';

const NotFoundPage = () => {
const navigate = useNavigate();
if (process.env.NODE_ENV === 'production') {
// eslint-disable-next-line import/namespace
Sentry.captureMessage('404 Page Not Found', {
extra: {
pathname: location.pathname
}
});
}
return (
<NotfoundWrapper>
<Space height={100} />
<Flex gap="sm" direction="column">
<Img src={'/notfound.png'} width={300} height={50} />
<Text typo="h1">오류가 발생했어요.</Text>
<Text typo="body1">요청하신 페이지를 찾을 수 없어요.</Text>
</Flex>
<ButtonContainer>
<Button
style={{ maxWidth: '100%' }}
onClick={() => {
navigate('/');
}}>
메인 화면으로 돌아가기
</Button>
</ButtonContainer>
</NotfoundWrapper>
);
};

export default NotFoundPage;

const Img = styled.img`
object-fit: cover;
`;

const NotfoundWrapper = styled.div`
display: flex;
position: relative;
flex-direction: column;
justify-content: start;
align-items: center;
min-height: calc(100vh - ${GlobalSize.header});
width: ${GlobalSize.width};
margin: 0px -16px;
padding: 0px 16px;
padding-top: 40px;
padding-bottom: 28px;
background-color: ${color.backgroundAlternative};
${media.mobile} {
width: 100vw;
}
`;

const ButtonContainer = styled.div`
position: absolute;
bottom: 1.75rem;
padding: 1rem 0.75rem;
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
`;
1 change: 1 addition & 0 deletions src/pages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export * from './redirect/StudentVerificationServerRedirect';
export * from './PaymentsCheckout';
export * from './PaymentsFail';
export * from './PaymentsSuccess';
export * from './NotFound';
8 changes: 5 additions & 3 deletions src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import RoutePath from '@/routes/routePath';
import { RouterProvider, createBrowserRouter } from 'react-router-dom';
import Layout from '@/components/layout/Layout';
import AuthAccessGuard from '@/components/auth/guard/AuthAccessGuard';
import { Text } from '@/components/common/Wrapper';
import NotFoundPage from '@/pages/NotFound';
import {
AuthServerRedirectNavigate,
StudentVerificationServerRedirect,
Expand Down Expand Up @@ -148,8 +148,10 @@ const router = sentryCreateBrowserRouter([
path: RoutePath.PaymentsSuccess,
element: <PaymentsSuccess />
},
// Todo: 404 Not found page
{ path: '*', element: <Text>not found page</Text> }
{
path: '*',
element: <NotFoundPage />
}
]
}
]);
1 change: 0 additions & 1 deletion src/utils/sentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const setSentry = () => {
function initSentry() {
if (process.env.NODE_ENV === 'development') return;

console.log(`VERCEL ENV : ${process.env.VERCEL_ENV}`);
Sentry.init({
environment: process.env.VERCEL_ENV,
dsn: SENTRY_DSN_KEY,
Expand Down

0 comments on commit c59ec53

Please sign in to comment.