Skip to content

Commit

Permalink
Using hook instead of props
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasvoelcker committed Apr 11, 2024
1 parent 50705e6 commit c9f9160
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion client/src/utils/api.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import React from 'react';
import axios from 'axios';
import { toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
import { useNavigate } from 'react-router-dom';

const configs = {
withCredentials: true
};

const handleError = err => {
const navigate = useNavigate();

let error = {
status: err.response ? err.response.status : '',
message: err.response ? err.response.data.message : 'Internal Server Error',
Expand All @@ -24,7 +27,7 @@ const handleError = err => {
if (err.response && err.response.status < 500) {
if (err.response.status === 401 || err.response.status === 403) {
localStorage.setItem('toastMessage', error.message);
this.props.router.navigate({ pathname: '/ui/login' }, { replace: true });
navigate({ pathname: '/ui/login' }, { replace: true });
} else {
toast.warn(error.message);
}
Expand Down

0 comments on commit c9f9160

Please sign in to comment.