From 6aeac9f280dc62a1b93f7de32ecce97befd41a42 Mon Sep 17 00:00:00 2001 From: chaaerim Date: Sun, 26 Feb 2023 22:01:14 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20axios=20request=20interceptors=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/client.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/apis/client.ts b/src/apis/client.ts index 1a1f4ed..3e37d3e 100644 --- a/src/apis/client.ts +++ b/src/apis/client.ts @@ -90,6 +90,23 @@ axiosClient.interceptors.response.use( ) ); +// 1. 요청 인터셉터 +axiosClient.interceptors.request.use( + function (config) { + if (config?.headers == null) { + throw new Error(`config.header is undefined`); + } + config.headers['Content-Type'] = 'application/json; charset=utf-8'; + config.headers['Authorization'] = authToken.access; + + return config; + }, + function (error) { + return Promise.reject(error); + } +); + +// 2. 응답 인터셉터 axiosClient.interceptors.response.use( response => response.data, async function (error: EffError) {