Files
it-incubator-todolist-ts-17…/src/utils/error-utils.ts

24 lines
621 B
TypeScript

import { setAppError, setAppStatus } from 'app/app-reducer'
import { Response } from 'api/todolists-api'
import { Dispatch } from 'redux'
export const handleServerAppError = <D>(
data: Response<D>,
dispatch: Dispatch
) => {
if (data.messages.length) {
dispatch(setAppError(data.messages[0]))
} else {
dispatch(setAppError('Some error occurred'))
}
dispatch(setAppStatus('failed'))
}
export const handleServerNetworkError = (
error: { message: string },
dispatch: Dispatch
) => {
dispatch(setAppError(error.message ? error.message : 'Some error occurred'))
dispatch(setAppStatus('failed'))
}