mirror of
https://github.com/ershisan99/it-incubator-todolist-ts-17-live-2024-08-17.git
synced 2026-02-04 21:02:13 +00:00
24 lines
621 B
TypeScript
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'))
|
|
}
|