Skip to content

Commit 32aef46

Browse files
committed
chore: fix react error in error handling
1 parent f22f403 commit 32aef46

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+166
-139
lines changed

src/GZCTF/ClientApp/src/components/GameChallengeModal.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { Icon } from '@mdi/react'
66
import React, { FC, useEffect, useState } from 'react'
77
import { useTranslation } from 'react-i18next'
88
import { ChallengeModal } from '@Components/ChallengeModal'
9-
import { showApiError } from '@Utils/ApiHelper'
109
import { encryptApiData } from '@Utils/Crypto'
10+
import { showErrorMsg } from '@Utils/Shared'
1111
import { ChallengeCategoryItemProps } from '@Utils/Shared'
1212
import { useConfig } from '@Hooks/useConfig'
1313
import api, { AnswerResult, ChallengeType, SubmissionType } from '@Api'
@@ -65,7 +65,7 @@ export const GameChallengeModal: FC<GameChallengeModalProps> = (props) => {
6565
icon: <Icon path={mdiCheck} size={1} />,
6666
})
6767
} catch (e) {
68-
showApiError(e, t)
68+
showErrorMsg(e, t)
6969
} finally {
7070
setDisabled(false)
7171
}
@@ -93,7 +93,7 @@ export const GameChallengeModal: FC<GameChallengeModalProps> = (props) => {
9393
icon: <Icon path={mdiCheck} size={1} />,
9494
})
9595
} catch (e) {
96-
showApiError(e, t)
96+
showErrorMsg(e, t)
9797
}
9898
}
9999

@@ -120,7 +120,7 @@ export const GameChallengeModal: FC<GameChallengeModalProps> = (props) => {
120120
},
121121
})
122122
} catch (e) {
123-
showApiError(e, t)
123+
showErrorMsg(e, t)
124124
} finally {
125125
setDisabled(false)
126126
}
@@ -153,7 +153,7 @@ export const GameChallengeModal: FC<GameChallengeModalProps> = (props) => {
153153
autoClose: false,
154154
})
155155
} catch (e) {
156-
showApiError(e, t)
156+
showErrorMsg(e, t)
157157
setDisabled(false)
158158
}
159159
}
@@ -174,7 +174,7 @@ export const GameChallengeModal: FC<GameChallengeModalProps> = (props) => {
174174
} catch (err) {
175175
setDisabled(false)
176176
setFlag('')
177-
showApiError(err, t)
177+
showErrorMsg(err, t)
178178
clearInterval(polling)
179179
}
180180
}, 500)

src/GZCTF/ClientApp/src/components/HashPow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { forwardRef, useState, useEffect, useImperativeHandle } from 'react'
44
import { useTranslation } from 'react-i18next'
55
import { CaptchaInstance } from '@Components/Captcha'
66
import { PowWorker } from '@Components/icon/PowWorker'
7-
import { showApiError } from '@Utils/ApiHelper'
87
import workerScript from '@Utils/PowWorker'
8+
import { showErrorMsg } from '@Utils/Shared'
99
import api, { HashPowChallenge } from '@Api'
1010
import classes from '@Styles/HashPow.module.css'
1111

@@ -43,7 +43,7 @@ export const usePowChallenge = () => {
4343
})
4444
}
4545
} catch (e) {
46-
showApiError(e, t)
46+
showErrorMsg(e, t)
4747
return null
4848
}
4949
}

src/GZCTF/ClientApp/src/components/PasswordChangeModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { FC } from 'react'
77
import { useTranslation } from 'react-i18next'
88
import { useNavigate } from 'react-router'
99
import { StrengthPasswordInput } from '@Components/StrengthPasswordInput'
10-
import { showApiError } from '@Utils/ApiHelper'
1110
import { encryptApiData } from '@Utils/Crypto'
11+
import { showErrorMsg } from '@Utils/Shared'
1212
import { useConfig } from '@Hooks/useConfig'
1313
import api from '@Api'
1414

@@ -45,7 +45,7 @@ export const PasswordChangeModal: FC<ModalProps> = (props) => {
4545
api.account.accountLogOut()
4646
navigate('/account/login')
4747
} catch (e) {
48-
showApiError(e, t)
48+
showErrorMsg(e, t)
4949
}
5050
} else {
5151
showNotification({

src/GZCTF/ClientApp/src/components/TeamCreateModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { mdiCheck, mdiCloseCircle } from '@mdi/js'
1515
import { Icon } from '@mdi/react'
1616
import { FC, useState } from 'react'
1717
import { Trans, useTranslation } from 'react-i18next'
18-
import { showApiError } from '@Utils/ApiHelper'
18+
import { showErrorMsg } from '@Utils/Shared'
1919
import api, { TeamUpdateModel } from '@Api'
2020

2121
interface TeamEditModalProps extends ModalProps {
@@ -46,7 +46,7 @@ export const TeamCreateModal: FC<TeamEditModalProps> = (props) => {
4646
mutate()
4747
modalProps.onClose()
4848
} catch (e) {
49-
showApiError(e, t)
49+
showErrorMsg(e, t)
5050
} finally {
5151
setDisabled(false)
5252
}

src/GZCTF/ClientApp/src/components/TeamEditModal.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { mdiCheck, mdiClose, mdiRefresh, mdiStar } from '@mdi/js'
2626
import { Icon } from '@mdi/react'
2727
import { FC, useEffect, useState } from 'react'
2828
import { useTranslation } from 'react-i18next'
29-
import { showApiError, tryGetErrorMsg } from '@Utils/ApiHelper'
29+
import { showErrorMsg, tryGetErrorMsg } from '@Utils/Shared'
3030
import { IMAGE_MIME_TYPES } from '@Utils/Shared'
3131
import api, { TeamInfoModel, TeamUserInfoModel } from '@Api'
3232
import misc from '@Styles/Misc.module.css'
@@ -131,7 +131,7 @@ export const TeamEditModal: FC<TeamEditModalProps> = (props) => {
131131
setTeamInfo(null)
132132
props.onClose()
133133
} catch (e) {
134-
showApiError(e, t)
134+
showErrorMsg(e, t)
135135
}
136136
}
137137

@@ -154,7 +154,7 @@ export const TeamEditModal: FC<TeamEditModalProps> = (props) => {
154154
)
155155
props.onClose()
156156
} catch (e) {
157-
showApiError(e, t)
157+
showErrorMsg(e, t)
158158
}
159159
}
160160

@@ -178,7 +178,7 @@ export const TeamEditModal: FC<TeamEditModalProps> = (props) => {
178178
}
179179
)
180180
} catch (e) {
181-
showApiError(e, t)
181+
showErrorMsg(e, t)
182182
}
183183
}
184184

@@ -200,7 +200,7 @@ export const TeamEditModal: FC<TeamEditModalProps> = (props) => {
200200
}
201201
)
202202
} catch (e) {
203-
showApiError(e, t)
203+
showErrorMsg(e, t)
204204
}
205205
}
206206

@@ -216,7 +216,7 @@ export const TeamEditModal: FC<TeamEditModalProps> = (props) => {
216216
icon: <Icon path={mdiCheck} size={1} />,
217217
})
218218
} catch (e) {
219-
showApiError(e, t)
219+
showErrorMsg(e, t)
220220
}
221221
}
222222

@@ -286,7 +286,7 @@ export const TeamEditModal: FC<TeamEditModalProps> = (props) => {
286286
}
287287
)
288288
} catch (e) {
289-
showApiError(e, t)
289+
showErrorMsg(e, t)
290290
}
291291
}
292292

src/GZCTF/ClientApp/src/components/WriteupSubmitModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import dayjs from 'dayjs'
2222
import { FC, useEffect, useState } from 'react'
2323
import { Trans, useTranslation } from 'react-i18next'
2424
import { Markdown } from '@Components/MarkdownRenderer'
25-
import { showApiError } from '@Utils/ApiHelper'
2625
import { useLanguage } from '@Utils/I18n'
26+
import { showErrorMsg } from '@Utils/Shared'
2727
import { HunamizeSize } from '@Utils/Shared'
2828
import { OnceSWRConfig } from '@Hooks/useConfig'
2929
import api from '@Api'
@@ -79,7 +79,7 @@ export const WriteupSubmitModal: FC<WriteupSubmitModalProps> = ({ gameId, writeu
7979
mutate()
8080
setDisabled(false)
8181
} catch (err) {
82-
showApiError(err, t)
82+
showErrorMsg(err, t)
8383
} finally {
8484
setProgress(0)
8585
setDisabled(false)

src/GZCTF/ClientApp/src/components/WsrxProvider.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Icon } from '@mdi/react'
55
import { Wsrx, WsrxError, WsrxErrorKind, WsrxFeature, WsrxOptions, WsrxState } from '@xdsec/wsrx'
66
import { t } from 'i18next'
77
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react'
8-
import { showApiError } from '@Utils/ApiHelper'
8+
import { showErrorMsg } from '@Utils/Shared'
99
import { useConfig } from '@Hooks/useConfig'
1010

1111
interface CustomWsrxOptions {
@@ -60,7 +60,7 @@ export const HandleWsrxError = (err: unknown, t: (key: string) => string) => {
6060
})
6161
}
6262
} else {
63-
showApiError(err, t)
63+
showErrorMsg(err, t)
6464
}
6565
}
6666

src/GZCTF/ClientApp/src/components/admin/AttachmentRemoteEditModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Icon } from '@mdi/react'
55
import { FC, useEffect, useState } from 'react'
66
import { useTranslation } from 'react-i18next'
77
import { useParams } from 'react-router'
8-
import { showApiError } from '@Utils/ApiHelper'
8+
import { showErrorMsg } from '@Utils/Shared'
99
import { useEditChallenge } from '@Hooks/useEdit'
1010
import api, { FileType, FlagCreateModel } from '@Api'
1111
import misc from '@Styles/Misc.module.css'
@@ -54,7 +54,7 @@ export const AttachmentRemoteEditModal: FC<ModalProps> = (props) => {
5454
mutate()
5555
props.onClose()
5656
} catch (e) {
57-
showApiError(e, t)
57+
showErrorMsg(e, t)
5858
} finally {
5959
setDisabled(false)
6060
}

src/GZCTF/ClientApp/src/components/admin/AttachmentUploadModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { Icon } from '@mdi/react'
2323
import { FC, useState } from 'react'
2424
import { useTranslation } from 'react-i18next'
2525
import { useParams } from 'react-router'
26-
import { showApiError } from '@Utils/ApiHelper'
26+
import { showErrorMsg } from '@Utils/Shared'
2727
import { useEditChallenge } from '@Hooks/useEdit'
2828
import api, { FileType } from '@Api'
2929
import uploadClasses from '@Styles/Upload.module.css'
@@ -93,7 +93,7 @@ export const AttachmentUploadModal: FC<ModalProps> = (props) => {
9393
props.onClose()
9494
}
9595
} catch (err) {
96-
showApiError(err, t)
96+
showErrorMsg(err, t)
9797
} finally {
9898
setDisabled(false)
9999
}

src/GZCTF/ClientApp/src/components/admin/ChallengeCreateModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Icon } from '@mdi/react'
66
import { FC, useState } from 'react'
77
import { useTranslation } from 'react-i18next'
88
import { useNavigate, useParams } from 'react-router'
9-
import { showApiError } from '@Utils/ApiHelper'
9+
import { showErrorMsg } from '@Utils/Shared'
1010
import {
1111
ChallengeCategoryItem,
1212
ChallengeCategoryList,
@@ -54,7 +54,7 @@ export const ChallengeCreateModal: FC<ChallengeCreateModalProps> = (props) => {
5454
onAddChallenge(res.data)
5555
navigate(`/admin/games/${id}/challenges/${res.data.id}`)
5656
} catch (e) {
57-
showApiError(e, t)
57+
showErrorMsg(e, t)
5858
} finally {
5959
setDisabled(false)
6060
}

src/GZCTF/ClientApp/src/components/admin/FlagCreateModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Icon } from '@mdi/react'
66
import { FC, useState } from 'react'
77
import { Trans, useTranslation } from 'react-i18next'
88
import { useParams } from 'react-router'
9-
import { showApiError } from '@Utils/ApiHelper'
9+
import { showErrorMsg } from '@Utils/Shared'
1010
import { useEditChallenge } from '@Hooks/useEdit'
1111
import api from '@Api'
1212
import misc from '@Styles/Misc.module.css'
@@ -50,7 +50,7 @@ export const FlagCreateModal: FC<ModalProps> = (props) => {
5050
setFlags('')
5151
props.onClose()
5252
} catch (e) {
53-
showApiError(e, t)
53+
showErrorMsg(e, t)
5454
} finally {
5555
setDisabled(false)
5656
}

src/GZCTF/ClientApp/src/components/admin/GameCreateModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import dayjs from 'dayjs'
88
import { FC, useState } from 'react'
99
import { useTranslation } from 'react-i18next'
1010
import { useNavigate } from 'react-router'
11-
import { showApiError } from '@Utils/ApiHelper'
11+
import { showErrorMsg } from '@Utils/Shared'
1212
import api, { GameInfoModel } from '@Api'
1313

1414
interface GameCreateModalProps extends ModalProps {
@@ -52,7 +52,7 @@ export const GameCreateModal: FC<GameCreateModalProps> = (props) => {
5252
onAddGame(res.data)
5353
navigate(`/admin/games/${res.data.id}/info`)
5454
} catch (e) {
55-
showApiError(e, t)
55+
showErrorMsg(e, t)
5656
setDisabled(false)
5757
}
5858
}

src/GZCTF/ClientApp/src/components/admin/GameNoticeEditModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Icon } from '@mdi/react'
55
import { FC, useEffect, useState } from 'react'
66
import { useTranslation } from 'react-i18next'
77
import { useParams } from 'react-router'
8-
import { showApiError } from '@Utils/ApiHelper'
8+
import { showErrorMsg } from '@Utils/Shared'
99
import api, { GameNotice } from '@Api'
1010

1111
interface GameNoticeEditModalProps extends ModalProps {
@@ -58,7 +58,7 @@ export const GameNoticeEditModal: FC<GameNoticeEditModalProps> = (props) => {
5858
mutateGameNotice(res.data)
5959
modalProps.onClose()
6060
} catch (e) {
61-
showApiError(e, t)
61+
showErrorMsg(e, t)
6262
} finally {
6363
setDisabled(false)
6464
setContent('')

src/GZCTF/ClientApp/src/components/admin/PDFViewer.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next'
55
import { Document, Page, pdfjs } from 'react-pdf'
66
import 'react-pdf/dist/esm/Page/AnnotationLayer.css'
77
import 'react-pdf/dist/esm/Page/TextLayer.css'
8-
import { showApiError } from '@Utils/ApiHelper'
8+
import { showErrorMsg } from '@Utils/Shared'
99
import classes from '@Styles/PDFViewer.module.css'
1010

1111
pdfjs.GlobalWorkerOptions.workerSrc = new URL('pdfjs-dist/build/pdf.worker.min.mjs', import.meta.url).toString()
@@ -33,7 +33,7 @@ export const PDFViewer: FC<PDFViewerProps> = ({ url, height }) => {
3333
<Text>{t('admin.content.games.writeups.pdf_fallback')}</Text>
3434
</Center>
3535
}
36-
onError={(e) => showApiError(e, t)}
36+
onError={(e) => showErrorMsg(e, t)}
3737
>
3838
<Box
3939
className={classes.box}
@@ -48,7 +48,7 @@ export const PDFViewer: FC<PDFViewerProps> = ({ url, height }) => {
4848
onLoadSuccess={({ numPages }) => {
4949
setNumPages(numPages)
5050
}}
51-
onLoadError={(e) => showApiError(e, t)}
51+
onLoadError={(e) => showErrorMsg(e, t)}
5252
>
5353
<Stack ref={ref}>
5454
{Array.from(Array.from({ length: numPages }), (_, index) => (

src/GZCTF/ClientApp/src/components/admin/TeamEditModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { mdiCheck, mdiLockOutline, mdiStar } from '@mdi/js'
1818
import { Icon } from '@mdi/react'
1919
import { FC, useEffect, useState } from 'react'
2020
import { useTranslation } from 'react-i18next'
21-
import { showApiError } from '@Utils/ApiHelper'
21+
import { showErrorMsg } from '@Utils/Shared'
2222
import api, { AdminTeamModel, TeamInfoModel } from '@Api'
2323

2424
interface TeamEditModalProps extends ModalProps {
@@ -59,7 +59,7 @@ export const TeamEditModal: FC<TeamEditModalProps> = (props) => {
5959
})
6060
modalProps.onClose()
6161
} catch (e) {
62-
showApiError(e, t)
62+
showErrorMsg(e, t)
6363
} finally {
6464
setDisabled(false)
6565
}

src/GZCTF/ClientApp/src/components/admin/UserEditModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { Icon } from '@mdi/react'
1919
import dayjs from 'dayjs'
2020
import { FC, useEffect, useState } from 'react'
2121
import { useTranslation } from 'react-i18next'
22-
import { showApiError } from '@Utils/ApiHelper'
22+
import { showErrorMsg } from '@Utils/Shared'
2323
import { useUser } from '@Hooks/useUser'
2424
import api, { AdminUserInfoModel, Role, UserInfoModel } from '@Api'
2525

@@ -64,7 +64,7 @@ export const UserEditModal: FC<UserEditModalProps> = (props) => {
6464
mutateUser({ ...user, ...profile })
6565
modalProps.onClose()
6666
} catch (e) {
67-
showApiError(e, t)
67+
showErrorMsg(e, t)
6868
} finally {
6969
setDisabled(false)
7070
}

src/GZCTF/ClientApp/src/pages/Index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { RecentGame } from '@Components/RecentGame'
99
import { WithNavBar } from '@Components/WithNavbar'
1010
import { MobilePostCard } from '@Components/mobile/PostCard'
1111
import { RecentGameCarousel } from '@Components/mobile/RecentGameCarousel'
12-
import { showApiError } from '@Utils/ApiHelper'
12+
import { showErrorMsg } from '@Utils/Shared'
1313
import { useIsMobile } from '@Utils/ThemeOverride'
1414
import { useRecentGames } from '@Hooks/useGame'
1515
import { usePageTitle } from '@Hooks/usePageTitle'
@@ -48,7 +48,7 @@ const Home: FC = () => {
4848
}
4949
api.info.mutateInfoGetPosts()
5050
} catch (e) {
51-
showApiError(e, t)
51+
showErrorMsg(e, t)
5252
} finally {
5353
setDisabled(false)
5454
}

0 commit comments

Comments
 (0)