Skip to content

Commit

Permalink
jump to login when token error
Browse files Browse the repository at this point in the history
  • Loading branch information
basefas committed Aug 7, 2020
1 parent 1a67efa commit 57e1d35
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/utils/request.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import axios from 'axios'
import {getToken} from "./auth";
import {message} from "antd";
import {deleteToken, getToken} from "./auth";
import {message, Modal} from "antd";

const { confirm } = Modal;

const instance = axios.create({
baseURL: 'http://127.0.0.1:8086',
Expand All @@ -18,7 +20,21 @@ instance.interceptors.request.use(

instance.interceptors.response.use(
response => {
return Promise.resolve(response.data);
if (response.data.code === -2) {
confirm({
title: ' Token 失效, 请重新登录!',
onOk() {
window.location.href = '/login'
deleteToken();
},
onCancel() {
deleteToken();
},
});
return Promise.resolve(response.data);
} else {
return Promise.resolve(response.data);
}
},
error => {
if (error.response) {
Expand Down

0 comments on commit 57e1d35

Please sign in to comment.