Skip to content

Commit

Permalink
Merge branch 'feature/AB#18112' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefwint committed Jun 11, 2024
2 parents c45d11e + cb8513a commit f424c6f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/App/Routes/AppRoutes.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useCallback, useLayoutEffect } from 'react'
import { useErrorBoundary } from 'react-error-boundary'
import { useNavigate, useRoutes } from 'react-router-dom'

import * as models from '@/config/objects'
Expand Down Expand Up @@ -43,10 +44,14 @@ import {
ThemeOverview,
} from '@/pages/public'
import MaintenancePage from '@/pages/public/MaintenancePage/MaintenancePage'
import globalErrorBoundary from '@/utils/globalErrorBoundary'

import ProtectedRoute from './ProtectedRoute'

const AppRoutes = () => {
const { showBoundary } = useErrorBoundary()
globalErrorBoundary.showBoundary = showBoundary

const routes = useRoutes([
/**
* Public pages
Expand Down
3 changes: 2 additions & 1 deletion src/api/instance.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import axios, { AxiosError, AxiosRequestConfig } from 'axios'

import getApiUrl from '@/utils/getApiUrl'
import globalErrorBoundary from '@/utils/globalErrorBoundary'
import globalRouter from '@/utils/globalRouter'
import { toastNotification } from '@/utils/toastNotification'

Expand Down Expand Up @@ -33,7 +34,7 @@ instance.interceptors.response.use(
toastNotification('notLoggedIn')
globalRouter.navigate?.('/login')
} else if (error.response?.status === 500) {
globalRouter.navigate?.('/500')
globalErrorBoundary.showBoundary?.(error)
}

return Promise.reject(error)
Expand Down
5 changes: 5 additions & 0 deletions src/utils/globalErrorBoundary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const globalErrorBoundary = { showBoundary: null } as {
showBoundary: ((error: any) => void) | null
}

export default globalErrorBoundary

0 comments on commit f424c6f

Please sign in to comment.