Skip to content

Commit 832cab9

Browse files
committed
Make better error displayment
1 parent c9d8bb9 commit 832cab9

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

src/app/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@ export function getConfig() {
3232
}
3333
return config;
3434
}
35+
36+
export function isNotProduction() {
37+
return !!process.env.DEBUG || !process.env.NODE_ENV || process.env.NODE_ENV !== 'production';
38+
}

src/app/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ export function isSerializedError(error: any): error is SerializedError {
2828
}
2929

3030
export function isFetchBaseQueryError(error: any): error is FetchBaseQueryError {
31-
return 'data' in error && 'status' in error;
31+
return 'data' in error && 'status' in error && typeof error.data === 'object';
3232
}

src/pages/Login/Login.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { getConfig } from '../../app/config';
1+
import { FetchBaseQueryError } from '@reduxjs/toolkit/dist/query';
2+
import { getConfig, isNotProduction } from '../../app/config';
23
import { useAuth } from '../../hooks/useAuth';
34
import Container from '@mui/material/Container';
45
import CssBaseline from '@mui/material/CssBaseline';
@@ -9,7 +10,6 @@ import Button from '@mui/material/Button';
910
import LockOutlinedIcon from '@mui/icons-material/LockOutlined';
1011
import GitHubIcon from '@mui/icons-material/GitHub';
1112
import Alert from '@mui/material/Alert';
12-
import { useAuth } from '../../hooks/useAuth';
1313

1414
const { githubClientId } = getConfig();
1515

@@ -30,7 +30,9 @@ export default function Login() {
3030
>
3131
{error && (
3232
<Alert severity="error" sx={{ m: 3 }}>
33-
{JSON.stringify(error)}
33+
{isNotProduction()
34+
? JSON.stringify(error)
35+
: ((error as FetchBaseQueryError)?.data as Record<string, any>)?.message}
3436
</Alert>
3537
)}
3638

0 commit comments

Comments
 (0)