-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
308b571
commit 0e1b74e
Showing
6 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import type { ReactNode } from 'react'; | ||
import { Component, type PropsWithChildren } from 'react'; | ||
|
||
import CommonErrorScreen from './ErrorScreen'; | ||
|
||
interface ErrorBoundaryProps { | ||
errorFallBack?: ReactNode; | ||
onError?: (error: Error) => void; | ||
} | ||
|
||
class ErrorBoundary extends Component< | ||
PropsWithChildren<ErrorBoundaryProps>, | ||
{ error: Error | null } | ||
> { | ||
error = null; | ||
|
||
componentDidCatch(error: Error) { | ||
if (this.props.onError) { | ||
this.setState({ | ||
error, | ||
}); | ||
} | ||
} | ||
|
||
render() { | ||
const { error } = this.state; | ||
|
||
if (error) { | ||
if (this.props.errorFallBack) { | ||
return this.props.errorFallBack; | ||
} | ||
|
||
return <CommonErrorScreen error={error} />; | ||
} | ||
|
||
return this.props.children; | ||
} | ||
} | ||
|
||
export default ErrorBoundary; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
interface CommonErrorScreenProps { | ||
error: Error; | ||
} | ||
|
||
// TODO: 의도되지 않은 에러에 대한 공통 스크린 정의 (404, 400, 500 등은 에러 페이지로 구현) | ||
const CommonErrorScreen = ({ error }: CommonErrorScreenProps) => { | ||
if (!error) { | ||
window.location.reload(); | ||
} | ||
|
||
return <>{JSON.stringify(error)}</>; | ||
}; | ||
|
||
export default CommonErrorScreen; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { type PropsWithChildren, type ReactNode, Suspense } from 'react'; | ||
|
||
import LoadingView from '../Loading'; | ||
import ErrorBoundary from './components/ErrorBoundary'; | ||
|
||
interface AsyncBoundaryProps { | ||
loadingFallback?: ReactNode; | ||
} | ||
|
||
const AsyncBoundary = ({ | ||
children, | ||
loadingFallback = <LoadingView />, | ||
}: PropsWithChildren<AsyncBoundaryProps>) => { | ||
return ( | ||
<ErrorBoundary> | ||
<Suspense fallback={loadingFallback}>{children}</Suspense> | ||
</ErrorBoundary> | ||
); | ||
}; | ||
|
||
export default AsyncBoundary; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const Spinner = () => { | ||
return <>spinner</>; | ||
}; | ||
|
||
export default Spinner; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { FC } from 'react'; | ||
|
||
import Spinner from './components/Spinner'; | ||
|
||
type LoadingViewType = 'spinner'; | ||
|
||
interface LoadingViewProps { | ||
type?: LoadingViewType; | ||
} | ||
|
||
const LoadingView: FC<LoadingViewProps> = ({ type = 'spinner' }) => { | ||
switch (type) { | ||
default: | ||
return <Spinner />; | ||
} | ||
}; | ||
|
||
export default LoadingView; |
Empty file.