Skip to content

Commit

Permalink
ui: fix the error message doesn't show correct (#799)
Browse files Browse the repository at this point in the history
  • Loading branch information
baurine authored Nov 23, 2020
1 parent 1ff0f33 commit d03c863
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions ui/lib/client/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export enum ErrorStrategy {
Default = 'default',
Custom = 'custom',
}
const ERR_CODE_OTHER = 'error.api.other'

function initAxios() {
i18n.addTranslations(require.context('./translations/', false, /\.yaml$/))
Expand All @@ -50,15 +51,18 @@ function initAxios() {
const method = (config.method as string).toLowerCase()

let errCode: string
let content: string
if (err.message === 'Network Error') {
errCode = 'error.network'
} else {
errCode = response?.data?.code || 'error.api.other'
if (errCode === 'error.api.other') {
errCode = response?.data?.message || err.message
}
errCode = response?.data?.code
}
if (errCode !== ERR_CODE_OTHER && i18next.exists(errCode)) {
content = i18next.t(errCode)
} else {
content =
response?.data?.message || err.message || i18next.t(ERR_CODE_OTHER)
}
const content = i18next.t(errCode)
err.message = content

if (errCode === 'error.api.unauthorized') {
Expand Down

0 comments on commit d03c863

Please sign in to comment.