refactor: Update useAxios hook
This commit is contained in:
parent
4638846030
commit
7fd9ded5f8
@ -5,11 +5,22 @@ const AxiosType = {
|
||||
EXTERNAL: 'External',
|
||||
}
|
||||
|
||||
/**
|
||||
* axios 인스턴스 생성 후 반환
|
||||
* @param {String} lang
|
||||
* @returns http request instance - get, post, put, patch, delete (promise 접수사가 붙은 함수는 promise 반환)
|
||||
*/
|
||||
export function useAxios(lang = '') {
|
||||
const getInstances = (url) => {
|
||||
/**
|
||||
* url이 http로 시작하면 외부 서버로 판단
|
||||
*/
|
||||
let type = AxiosType.INTERNAL
|
||||
url.startsWith('http') ? (type = AxiosType.EXTERNAL) : ''
|
||||
|
||||
/**
|
||||
* 내부 서버로 요청 시 lang 헤더 추가
|
||||
*/
|
||||
let headerValue = {
|
||||
Accept: 'application/json',
|
||||
}
|
||||
@ -21,18 +32,13 @@ export function useAxios(lang = '') {
|
||||
})
|
||||
}
|
||||
|
||||
// request 추가 로직
|
||||
axios.interceptors.request.use((config) => {
|
||||
// config['Authorization'] = localStorage.getItem('token')
|
||||
//TODO: 인터셉터에서 추가 로직 구현
|
||||
return config
|
||||
})
|
||||
|
||||
axios.interceptors.request.use(undefined, (error) => {
|
||||
//TODO: 인터셉터에서 에러 처리 로직 구현
|
||||
// if (error.isAxiosError && e.response?.status === 401) {
|
||||
// localStorage.removeItem('token')
|
||||
// }
|
||||
})
|
||||
// response 추가 로직
|
||||
axios.interceptors.request.use(undefined, (error) => {})
|
||||
|
||||
const get = async ({ url }) => {
|
||||
return await getInstances(url)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user