응답 인터셉터 수정

This commit is contained in:
yoon 2025-02-11 10:33:09 +09:00
parent 7a9daa4732
commit c3b2bcec66

View File

@ -1,4 +1,5 @@
import axios from "axios"; import axios from "axios";
import { useRoute } from 'vue-router';
import { useToastStore } from '@s/toastStore'; import { useToastStore } from '@s/toastStore';
const $api = axios.create({ const $api = axios.create({
@ -37,11 +38,16 @@ $api.interceptors.response.use(
}, },
function (error) { function (error) {
const toastStore = useToastStore() const toastStore = useToastStore()
const currentPage = error.config.headers['X-Page-Route'];
// 오류 응답 처리 // 오류 응답 처리
if (error.response) { if (error.response) {
switch (error.response.status) { switch (error.response.status) {
case 401: case 401:
toastStore.onToast('아이디 혹은 비밀번호가 틀렸습니다.', 'e'); if (currentPage === '/login') {
toastStore.onToast('아이디 혹은 비밀번호가 틀렸습니다.', 'e');
} else {
toastStore.onToast('인증이 필요합니다.', 'e');
}
break; break;
case 403: case 403:
toastStore.onToast('접근 권한이 없습니다.', 'e'); toastStore.onToast('접근 권한이 없습니다.', 'e');