gpt4 book ai didi

vuejs2 - 使用 @nuxtjs/auth 捕获错误服务器响应

转载 作者:行者123 更新时间:2023-12-04 12:25:50 25 4
gpt4 key购买 nike

我正在 try catch @nuxtjs/auth 的错误响应,但它似乎除了未定义之外没有返回任何内容。

如果我包含用户,它会拒绝登录,所以我想知道它为什么返回未定义。

配置:

auth: {
strategies: {
local: {
endpoints: {
login: {
url: 'http://127.0.0.1:80/api/login',
method: 'post',
propertyName: 'token'
},
logout: false,
user: {
url: 'http://127.0.0.1:80/api/me',
method: 'get',
propertyName: undefined
}
},
tokenRequired: true,
tokenType: 'bearer',
}
},
plugins: [
'@/plugins/auth.js'
]
},

插入:
export default function ({ app }) {
app.$auth.onError((error, name, endpoint) => {
console.error(name, error)
});
}

查看功能:
- handleSuccess 和 handleFailure 都返回未定义。
login() {
this.toggleProcessing(0);

let payload = {
username: 'admin',
password: 'admin123'
}

let handleSuccess = response => {
console.log(response);
this.toggleProcessing(0);
}

let handleFailure = error => {
console.log(error);
this.toggleProcessing(0);
}

this.$auth.loginWith('local', { data: payload }).then(handleSuccess).catch(handleFailure);
},

最佳答案

您可以使用 e.response

async login() {
try {
const login = {
username: this.username,
password: this.password
}
let response = await this.$auth.loginWith('local', { data: login })
console.log('response', response)
} catch (e) {
console.log('Error Response', e.response)
}
}

关于vuejs2 - 使用 @nuxtjs/auth 捕获错误服务器响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52470507/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com