mirror of
https://github.com/ershisan99/it-incubator-todolist-ts-17-live-2024-08-17.git
synced 2026-02-05 05:12:08 +00:00
init
This commit is contained in:
17
src/utils/error-utils.ts
Normal file
17
src/utils/error-utils.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import {setAppErrorAC, SetAppErrorActionType, setAppStatusAC, SetAppStatusActionType} from '../app/app-reducer'
|
||||
import {ResponseType} from '../api/todolists-api'
|
||||
import {Dispatch} from 'redux'
|
||||
|
||||
export const handleServerAppError = <D>(data: ResponseType<D>, dispatch: Dispatch<SetAppErrorActionType | SetAppStatusActionType>) => {
|
||||
if (data.messages.length) {
|
||||
dispatch(setAppErrorAC(data.messages[0]))
|
||||
} else {
|
||||
dispatch(setAppErrorAC('Some error occurred'))
|
||||
}
|
||||
dispatch(setAppStatusAC('failed'))
|
||||
}
|
||||
|
||||
export const handleServerNetworkError = (error: { message: string }, dispatch: Dispatch<SetAppErrorActionType | SetAppStatusActionType>) => {
|
||||
dispatch(setAppErrorAC(error.message ? error.message : 'Some error occurred'))
|
||||
dispatch(setAppStatusAC('failed'))
|
||||
}
|
||||
Reference in New Issue
Block a user