ыввы
This commit is contained in:
Generated
+1643
-1143
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')
|
expect(getApiErrorMessage(new Error('Something broke'))).toBe('Something broke')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns unknown error for falsy input', () => {
|
it('returns null for falsy input (no error)', () => {
|
||||||
expect(getApiErrorMessage(null)).toBe('Произошла неизвестная ошибка')
|
expect(getApiErrorMessage(null)).toBeNull()
|
||||||
expect(getApiErrorMessage(undefined)).toBe('Произошла неизвестная ошибка')
|
expect(getApiErrorMessage(undefined)).toBeNull()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns unknown error for random object', () => {
|
it('returns unknown error for random object', () => {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { isAxiosError } from 'axios'
|
import { isAxiosError } from 'axios'
|
||||||
|
|
||||||
export function getApiErrorMessage(error: unknown): string {
|
export function getApiErrorMessage(error: unknown): string | null {
|
||||||
if (!error) return 'Произошла неизвестная ошибка'
|
if (!error) return null
|
||||||
|
|
||||||
if (isAxiosError(error)) {
|
if (isAxiosError(error)) {
|
||||||
if (error.response?.data?.error && typeof error.response.data.error === 'string') {
|
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,
|
onMutateResult: TOnMutateResult | undefined,
|
||||||
mutationContext: MutationFunctionContext,
|
mutationContext: MutationFunctionContext,
|
||||||
) => {
|
) => {
|
||||||
addNotification({ type: 'error', message: getApiErrorMessage(error) })
|
addNotification({ type: 'error', message: getApiErrorMessage(error) || 'Произошла неизвестная ошибка' })
|
||||||
onError?.(error, variables, onMutateResult, mutationContext)
|
onError?.(error, variables, onMutateResult, mutationContext)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user