fix some lint errors
This commit is contained in:
@@ -27,9 +27,9 @@ export const AuthUserProvider = ({children}: PropsWithChildren) => {
|
||||
try {
|
||||
const res = await axios.get('/api/user')
|
||||
setAuthUser(res.data)
|
||||
} catch (e) {
|
||||
// @ts-ignore
|
||||
if (e.response.status === 401) {
|
||||
} catch (error) {
|
||||
// @ts-expect-error 401 error to redirect
|
||||
if (error.response.status === 401) {
|
||||
console.info('no user login')
|
||||
if (!['/connexion', '/inscription'].includes(window.location.pathname)) {
|
||||
window.location.href = '/connexion'
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React, {useState} from "react"
|
||||
import axios from "axios"
|
||||
import axios, {AxiosError} from "axios"
|
||||
import {cleanErrorsForm, displayFormErrors} from "../utilities/form"
|
||||
|
||||
const useAxiosTools = (isLoading = false) => {
|
||||
@@ -12,11 +12,13 @@ const useAxiosTools = (isLoading = false) => {
|
||||
const axiosPut = axios.put
|
||||
const axiosDelete = axios.delete
|
||||
|
||||
const errorCatch = (error: any) => {
|
||||
if (error.response && error.response.status === 422) {
|
||||
displayFormErrors(error)
|
||||
} else {
|
||||
setError(error.response?.data.message || error.message)
|
||||
const errorCatch = (error: Error|AxiosError|unknown) => {
|
||||
if (axios.isAxiosError(error)) {
|
||||
(error.response?.status === 422)
|
||||
? displayFormErrors(error)
|
||||
: setError(error.response?.data.message || error.message)
|
||||
} else if (error instanceof Error) {
|
||||
setError(error.message)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user