-
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.
[SWM-360] Fix : SESSION_ERROR handling
- Loading branch information
Showing
4 changed files
with
58 additions
and
42 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 |
---|---|---|
@@ -1,27 +1,28 @@ | ||
'use client'; | ||
import { API_FETCH_ERROR, ErrorMessage } from '@/src/api/ErrorMessage'; | ||
import { API_FETCH_ERROR, ErrorMessage, SESSION_ERROR } from '@/src/api/ErrorMessage'; | ||
import useAuth from '@/src/hooks/useAuth'; | ||
import setErrorToast from '@/src/util/toast/setErrorToast'; | ||
import { useRouter } from 'next/navigation'; | ||
import { useEffect } from 'react'; | ||
|
||
export default function ErrorHandler({ | ||
export default async function ErrorHandler({ | ||
error, | ||
reset | ||
}: { | ||
error: Error; | ||
reset: () => void; | ||
}) { | ||
const router = useRouter(); | ||
const { logout } = useAuth(); | ||
|
||
useEffect(() => { | ||
if (error.cause === API_FETCH_ERROR) { | ||
setErrorToast(error); | ||
router.back(); | ||
} else if (error.cause === SESSION_ERROR) { | ||
setErrorToast(error); | ||
await logout(); | ||
} else { | ||
setErrorToast(new Error(ErrorMessage.DEFAULT)); | ||
} | ||
return () => router.refresh(); | ||
}, [error, router]); | ||
|
||
return null; | ||
} |
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 |
---|---|---|
@@ -1,26 +1,31 @@ | ||
'use client'; | ||
import { API_FETCH_ERROR, ErrorMessage } from '@/src/api/ErrorMessage'; | ||
import { | ||
API_FETCH_ERROR, | ||
ErrorMessage, | ||
SESSION_ERROR | ||
} from '@/src/api/ErrorMessage'; | ||
import useAuth from '@/src/hooks/useAuth'; | ||
import setErrorToast from '@/src/util/toast/setErrorToast'; | ||
import { useRouter } from 'next/navigation'; | ||
import { useEffect } from 'react'; | ||
|
||
export default function ErrorHandler({ | ||
export default async function ErrorHandler({ | ||
error, | ||
reset | ||
}: { | ||
error: Error; | ||
reset: () => void; | ||
}) { | ||
const router = useRouter(); | ||
const { logout } = useAuth(); | ||
|
||
useEffect(() => { | ||
if (error.cause === API_FETCH_ERROR) { | ||
setErrorToast(error); | ||
} else { | ||
setErrorToast(new Error(ErrorMessage.DEFAULT)); | ||
} | ||
return () => router.refresh(); | ||
}, [error, router]); | ||
if (error.cause === API_FETCH_ERROR) { | ||
setErrorToast(error); | ||
} else if (error.cause === SESSION_ERROR) { | ||
setErrorToast(error); | ||
await logout(); | ||
} else { | ||
setErrorToast(new Error(ErrorMessage.DEFAULT)); | ||
} | ||
|
||
return null; | ||
} |
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 |
---|---|---|
@@ -1,27 +1,32 @@ | ||
'use client'; | ||
import setErrorToast from '@/src/util/toast/setErrorToast'; | ||
import { useRouter } from 'next/navigation'; | ||
import { useEffect } from 'react'; | ||
import { API_FETCH_ERROR, ErrorMessage } from '../api/ErrorMessage'; | ||
import { | ||
API_FETCH_ERROR, | ||
ErrorMessage, | ||
SESSION_ERROR | ||
} from '../api/ErrorMessage'; | ||
import useAuth from '../hooks/useAuth'; | ||
|
||
export default function ErrorHandler({ | ||
export default async function ErrorHandler({ | ||
error, | ||
reset | ||
}: { | ||
error: Error; | ||
reset: () => void; | ||
}) { | ||
const router = useRouter(); | ||
const { logout } = useAuth(); | ||
|
||
useEffect(() => { | ||
if (error.cause === API_FETCH_ERROR) { | ||
setErrorToast(error); | ||
router.back(); | ||
} else { | ||
setErrorToast(new Error(ErrorMessage.DEFAULT)); | ||
} | ||
return () => router.refresh(); | ||
}, [error, router]); | ||
if (error.cause === API_FETCH_ERROR) { | ||
setErrorToast(error); | ||
router.back(); | ||
} else if (error.cause === SESSION_ERROR) { | ||
setErrorToast(error); | ||
await logout(); | ||
} else { | ||
setErrorToast(new Error(ErrorMessage.DEFAULT)); | ||
} | ||
|
||
return null; | ||
} |
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 |
---|---|---|
@@ -1,28 +1,33 @@ | ||
'use client'; | ||
import { API_FETCH_ERROR, ErrorMessage } from '@/src/api/ErrorMessage'; | ||
import { | ||
API_FETCH_ERROR, | ||
ErrorMessage, | ||
SESSION_ERROR | ||
} from '@/src/api/ErrorMessage'; | ||
import useAuth from '@/src/hooks/useAuth'; | ||
import setErrorToast from '@/src/util/toast/setErrorToast'; | ||
import { useRouter } from 'next/navigation'; | ||
import { useEffect } from 'react'; | ||
|
||
export default function ErrorHandler({ | ||
export default async function ErrorHandler({ | ||
error, | ||
reset | ||
}: { | ||
error: Error; | ||
reset: () => void; | ||
}) { | ||
const router = useRouter(); | ||
const { logout } = useAuth(); | ||
|
||
useEffect(() => { | ||
if (error.cause === API_FETCH_ERROR) { | ||
setErrorToast(error); | ||
router.replace('/'); | ||
router.refresh(); | ||
} else { | ||
setErrorToast(new Error(ErrorMessage.DEFAULT)); | ||
} | ||
return () => router.refresh(); | ||
}, [error, router]); | ||
if (error.cause === API_FETCH_ERROR) { | ||
setErrorToast(error); | ||
router.replace('/'); | ||
router.refresh(); | ||
} else if (error.cause === SESSION_ERROR) { | ||
setErrorToast(error); | ||
await logout(); | ||
} else { | ||
setErrorToast(new Error(ErrorMessage.DEFAULT)); | ||
} | ||
|
||
return null; | ||
} |