Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
({ response }) => {
//console.log(response.status);
// 对响应错误做点什么
switch (response.status) {
case 404:
Notification.error({
title: "请求页面不存在",
desc: response.data.message
});
router.replace('/404')
break;
default:
Notification.error({
title: "请求错误",
desc: response.data.message
});
break;
}
return Promise.reject(response);
}
);
.catch(e => {
if (e.code === 5000) {
const h = vm.$createElement.bind(vm)
Notification.error({
title: 'Error',
message: h('div', [
h(
'div',
{ style: 'word-break: break-all' },
'😢Invalid username or password.'
)
]),
position: 'bottom-right',
duration: 6000
})
}
// 仅用于触发 afterEach 后置导航守卫,使得顶部进度条 done()
// For invoking `router.afterEach` navigation guards including `NProgress.done()`
vm.$router.replace('/login')
console.error(`[Login error]: ${JSON.stringify(e)}`)
)
}
// 2. invalid access_token
if (data.code === 3000) {
// 触发 router 的 beforeEach 导航守卫中的 token 检测并重定向至 login 页
tokenInCookie.removeItem()
// 以下 action 用于用户登出,并重置 vuex 状态
return store
.dispatch('login/userLogout')
.then(() => Promise.reject(data))
}
// 3. error capture (Only capture error which has a error code)
if (data.code && data.code !== 2000) {
Notification.error({
title: 'Error',
message: h(
'div',
data.code === 3002
? [
'Unauthorized request',
h('div', { style: 'work-break: break-all' }, url)
]
: '😢Update data failed.'
),
position: 'bottom-right'
})
return Promise.reject(data)
}
// 4. normal response or binary data
{
confirmButtonText: '重新登录',
cancelButtonText: '取消',
type: 'warning'
}
).then(() => {
store.dispatch('LogOut').then(() => {
location.reload() // 为了重新实例化vue-router对象 避免bug
})
})
} else if (code === 403) {
router.push({ path: '/401' })
} else {
const errorMsg = error.response.data.message
if (errorMsg !== undefined) {
Notification.error({
title: errorMsg,
duration: 5000
})
}
}
} else {
Notification.error({
title: '接口请求失败',
duration: 5000
})
}
return Promise.reject(error)
}
)
doAction(actionData) {
var that = this;
if (!this.finalModel && !this.action.InstanceOptional) {
Notification.error({
title: "Error",
message: "Please select a " + this.action.OnType,
});
return
}
console.log("perform action", actionData, this.finalModel);
if (this.finalModel && Object.keys(this.finalModel).indexOf("id") > -1) {
actionData[this.action.OnType + "_id"] = this.finalModel["id"]
} else {
}
that.actionManager.doAction(that.action.OnType, that.action.Name, actionData).then(function () {
that.$emit("action-complete", that.action);
}, function () {
console.log("not clearing out the form")
});
},
}, function (res) {
console.log("action failed", res);
reject("Failed");
if (res.response.data.Message) {
Notification.error(res.response.data.Message)
} else {
Notification.error("Failed to " + window.titleCase(actionName))
}
})
}, function (err) {
that.loginFail = true
Notification.error({
title: '错误',
message: err.data.msg
})
})
error => {
let code = 0
try {
code = error.response.data.status
} catch (e) {
if (error.toString().indexOf('timeout')) {
Notification.error({
title: '错误',
message: '请求超时!'
})
return Promise.reject(error)
}
}
if (code === 401) {
detailBox.confirm(
'登录状态过期了哦,您可以继续留在该页面,或者重新登录',
'系统提示',
{
confirmButtonText: '重新登录',
cancelButtonText: '取消',
type: 'warning'
}
).then(() => {
save() {
let that = this
if (!this.currentUser.editMode && this.currentUser.password !== this.repassword) {
Notification.error('两次密码输入不一致')
return
}
this.currentUser.httpSave(function (response) {
Notification.success({
message: that.currentUser.editMode ? '修改用户成功!' : '创建用户成功!'
})
that.$router.go(-1)
})
}
},