Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] Axios 공용 인터셉터 추출 #1579

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

nerdchanii
Copy link

📌 개요

  • Axios 공용 인터셉터 추출

💻 작업사항

  • Axios 공용 인터셉터를 추출했습니다.

✅ 변경로직

  • axios의 인터셉터들의 콜백 함수들 선언해서 분리했습니다.

변경전

instance.interceptors.request.use(
  function setConfig(config) {
    config.headers = {
      'Content-Type': 'application/json',
      Authorization: `Bearer ${localStorage.getItem('42gg-token')}`,
    };
    config.withCredentials = true;
    return config;
  },
  function getError(error) {
    return Promise.reject(error);
  }
)

변경후

 instance.interceptors.request.use(setConfig, getError);
 instanceInManage.interceptors.request.use(setConfig, getError);
 instanceInPartyManage.interceptors.request.use(setConfig, getError);
 
 // 추출된 callback함수들
 function setConfig<T>(config: AxiosRequestConfig<T>) {
   return {
     ...config,
     headers: {
       ...config.headers,
       'Content-Type': 'application/json',
       Authorization: `Bearer ${localStorage.getItem('42gg-token') ?? ''}`,
       withCredentials: true,
     },
 };
 
 function getError(error) {
   return Promise.reject(error);
 }

💡관련 Issue

@nerdchanii nerdchanii added refactor 유지보수와 잠재적 오류를 방지하기 위한 refactor issue api api 호출 labels Dec 19, 2024
@nerdchanii nerdchanii self-assigned this Dec 19, 2024
@nerdchanii
Copy link
Author

nerdchanii commented Dec 19, 2024

@42organization/fe_8th macos-12 depreacted됨에 따라 main-build-test.yamlruns-on환경을 수정해야하는 것으로 보입니다.

ref

@nerdchanii nerdchanii force-pushed the Refactor/#1578-remove-duplicate-axios-interceptor branch from 8faf5dc to c914ed9 Compare December 23, 2024 07:40
@nerdchanii
Copy link
Author

close #1295

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api api 호출 refactor 유지보수와 잠재적 오류를 방지하기 위한 refactor issue
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

[Refactor] Axios interceptor 공통 로직 추출
1 participant