ыввы
This commit is contained in:
@@ -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)
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user