This commit is contained in:
Kirill
2026-05-28 11:47:53 +05:00
parent 3e00c402b5
commit ae36123fa7
4 changed files with 1649 additions and 1149 deletions
+1643 -1143
View File
File diff suppressed because it is too large Load Diff
@@ -24,9 +24,9 @@ describe('getApiErrorMessage', () => {
expect(getApiErrorMessage(new Error('Something broke'))).toBe('Something broke')
})
it('returns unknown error for falsy input', () => {
expect(getApiErrorMessage(null)).toBe('Произошла неизвестная ошибка')
expect(getApiErrorMessage(undefined)).toBe('Произошла неизвестная ошибка')
it('returns null for falsy input (no error)', () => {
expect(getApiErrorMessage(null)).toBeNull()
expect(getApiErrorMessage(undefined)).toBeNull()
})
it('returns unknown error for random object', () => {
@@ -1,7 +1,7 @@
import { isAxiosError } from 'axios'
export function getApiErrorMessage(error: unknown): string {
if (!error) return 'Произошла неизвестная ошибка'
export function getApiErrorMessage(error: unknown): string | null {
if (!error) return null
if (isAxiosError(error)) {
if (error.response?.data?.error && typeof error.response.data.error === 'string') {
@@ -35,7 +35,7 @@ export function useMutationWithToast<TData = unknown, TError = unknown, TVariabl
onMutateResult: TOnMutateResult | undefined,
mutationContext: MutationFunctionContext,
) => {
addNotification({ type: 'error', message: getApiErrorMessage(error) })
addNotification({ type: 'error', message: getApiErrorMessage(error) || 'Произошла неизвестная ошибка' })
onError?.(error, variables, onMutateResult, mutationContext)
},
})