Commit 84859bc2 authored by Yoon, Daeki's avatar Yoon, Daeki 😅
Browse files

Merge branch 'axios-error-handling'

parents 0efd8af2 e6f3e052
import axios from "axios";
import axios from "./axios.config";
import { IAnswer, IAnswerRequestData } from "../types";
import baseUrl from "./baseUrl";
......
import axios from "axios";
import axios from "./axios.config";
import { SignupUser } from "../types";
import baseUrl from "./baseUrl";
......
import axios from "axios";
const customAxios = axios.create();
export default customAxios;
......@@ -3,3 +3,5 @@ export * as questionApi from "./question.api";
export * as surveyApi from "./survey.api";
export * as answerApi from "./answer.api";
export { baseImageUrl } from "./baseUrl";
export { default as customAxios } from "./axios.config";
export { useAxiosInterceptor } from "./useAxiosInterceptor";
import axios from "axios";
import axios from "./axios.config";
import { IQuestionData } from "../types";
import baseUrl from "./baseUrl";
......
import axios from "axios";
import axios from "./axios.config";
import { CreateQuestionData, IQuestionData, ISurvey } from "../types";
import baseUrl from "./baseUrl";
......
import { useEffect } from "react";
import { NavigateFunction, useLocation } from "react-router-dom";
import customAxios from "./axios.config";
export const useAxiosInterceptor = (navigate: NavigateFunction) => {
const location = useLocation();
useEffect(() => {
const responseInterceptor = customAxios.interceptors.response.use(
(response) => response,
(error) => {
if (error.response.status === 401) {
navigate("/login", {
replace: true,
state: { from: location.pathname },
});
}
return Promise.reject(error);
}
);
return () => {
customAxios.interceptors.response.eject(responseInterceptor);
};
}, []);
};
import React from "react";
import { Outlet } from "react-router-dom";
import { Outlet, useNavigate } from "react-router-dom";
import { useAxiosInterceptor } from "../apis";
import { AuthProvider } from "../auth";
import { Header } from "../commons";
export const BaseLayout = () => {
const navigate = useNavigate();
useAxiosInterceptor(navigate);
return (
<AuthProvider>
<Header />
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment