Skip to content

Instantly share code, notes, and snippets.

View ereminmaksim's full-sized avatar
:octocat:
Working from home

Maksim Eremin ereminmaksim

:octocat:
Working from home
View GitHub Profile
@ereminmaksim
ereminmaksim / error-utils.ts
Created July 1, 2022 16:57 — forked from safronman/error-utils.ts
axios catch TS error
import { setAppErrorAC, SetAppErrorActionType } from '../../app/app-reducer';
import { Dispatch } from 'redux';
import axios, { AxiosError } from 'axios';
import { AppThunk } from '../../app/store';
import { packsAPI } from '../../api/packs-api';
export const errorUtils = (e: Error | AxiosError<{error: string}>, dispatch: Dispatch<SetAppErrorActionType>) => {
const err = e as Error | AxiosError<{ error: string }>
if (axios.isAxiosError(err)) {
const error = err.response?.data ? err.response.data.error : err.message