Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
survey
Commits
84859bc2
Commit
84859bc2
authored
Nov 15, 2022
by
Yoon, Daeki
😅
Browse files
Merge branch 'axios-error-handling'
parents
0efd8af2
e6f3e052
Changes
8
Hide whitespace changes
Inline
Side-by-side
frontend/src/apis/answer.api.ts
View file @
84859bc2
import
axios
from
"
axios
"
;
import
axios
from
"
./
axios
.config
"
;
import
{
IAnswer
,
IAnswerRequestData
}
from
"
../types
"
;
import
baseUrl
from
"
./baseUrl
"
;
...
...
frontend/src/apis/auth.api.ts
View file @
84859bc2
import
axios
from
"
axios
"
;
import
axios
from
"
./
axios
.config
"
;
import
{
SignupUser
}
from
"
../types
"
;
import
baseUrl
from
"
./baseUrl
"
;
...
...
frontend/src/apis/axios.config.ts
0 → 100644
View file @
84859bc2
import
axios
from
"
axios
"
;
const
customAxios
=
axios
.
create
();
export
default
customAxios
;
frontend/src/apis/index.ts
View file @
84859bc2
...
...
@@ -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
"
;
frontend/src/apis/question.api.ts
View file @
84859bc2
import
axios
from
"
axios
"
;
import
axios
from
"
./
axios
.config
"
;
import
{
IQuestionData
}
from
"
../types
"
;
import
baseUrl
from
"
./baseUrl
"
;
...
...
frontend/src/apis/survey.api.ts
View file @
84859bc2
import
axios
from
"
axios
"
;
import
axios
from
"
./
axios
.config
"
;
import
{
CreateQuestionData
,
IQuestionData
,
ISurvey
}
from
"
../types
"
;
import
baseUrl
from
"
./baseUrl
"
;
...
...
frontend/src/apis/useAxiosInterceptor.ts
0 → 100644
View file @
84859bc2
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
);
};
},
[]);
};
frontend/src/layouts/BaseLayout.tsx
View file @
84859bc2
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
/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment