enhancement(auth): better error message handling

Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
Erik Michelson 2023-03-25 18:58:48 +01:00
parent 8e57188ab5
commit ca9836d691
37 changed files with 199 additions and 207 deletions

View file

@ -18,7 +18,7 @@ export const NewPasswordField: React.FC<CommonFieldProps> = ({ onChange, value,
const { t } = useTranslation()
const isValid = useMemo(() => {
return value.trim() !== '' && value.length >= 8
return value.trim() !== ''
}, [value])
return (
@ -34,7 +34,6 @@ export const NewPasswordField: React.FC<CommonFieldProps> = ({ onChange, value,
onChange={onChange}
placeholder={t('login.auth.password') ?? undefined}
className='bg-dark text-light'
minLength={8}
autoComplete='new-password'
required
/>

View file

@ -19,14 +19,17 @@ exports[`Note loading boundary shows an error 1`] = `
</span>
<span>
titleI18nKey:
api.note.notFound.title
noteLoadingBoundary.error.notFound.title
</span>
<span>
descriptionI18nKey:
api.note.notFound.description
noteLoadingBoundary.error.notFound.description
</span>
<span>
children:
<span>
This is a mock for CreateNonExistingNoteHint
</span>
</span>
</div>
`;

View file

@ -3,6 +3,7 @@
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { ApiError } from '../../../api/common/api-error'
import * as getNoteModule from '../../../api/notes'
import type { Note } from '../../../api/notes/types'
import * as LoadingScreenModule from '../../../components/application-loader/loading-screen/loading-screen'
@ -87,7 +88,7 @@ describe('Note loading boundary', () => {
jest.spyOn(getNoteModule, 'getNote').mockImplementation((id) => {
expect(id).toBe(mockedNoteId)
return new Promise((resolve, reject) => {
setTimeout(() => reject(new Error('api.note.notFound')), 0)
setTimeout(() => reject(new ApiError(404, undefined, undefined)), 0)
})
})
}

View file

@ -3,6 +3,8 @@
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { ApiError } from '../../../api/common/api-error'
import { ErrorToI18nKeyMapper } from '../../../api/common/error-to-i18n-key-mapper'
import { LoadingScreen } from '../../application-loader/loading-screen/loading-screen'
import { CommonErrorPage } from '../../error-pages/common-error-page'
import { CustomAsyncLoadingBoundary } from '../async-loading-boundary/custom-async-loading-boundary'
@ -28,11 +30,18 @@ export const NoteLoadingBoundary: React.FC<PropsWithChildren> = ({ children }) =
const errorComponent = useMemo(() => {
if (error === undefined) {
return <></>
return null
}
const errorI18nKeyPrefix = new ErrorToI18nKeyMapper(error, 'noteLoadingBoundary.error')
.withHttpCode(404, 'notFound')
.withHttpCode(403, 'forbidden')
.withHttpCode(401, 'forbidden')
.orFallbackI18nKey('other')
return (
<CommonErrorPage titleI18nKey={`${error.message}.title`} descriptionI18nKey={`${error.message}.description`}>
<ShowIf condition={error.message === 'api.error.note.not_found'}>
<CommonErrorPage
titleI18nKey={`${errorI18nKeyPrefix}.title`}
descriptionI18nKey={`${errorI18nKeyPrefix}.description`}>
<ShowIf condition={error instanceof ApiError && error.statusCode === 404}>
<CreateNonExistingNoteHint onNoteCreated={loadNoteFromServer} />
</ShowIf>
</CommonErrorPage>