我正在使用django-rest-passwordreset进行忘记的密码恢复。在我的Vue.js中,我有一种设置新密码的方法。它可以工作,但是如果密码太短或太常见等等,我需要获得例外... 这是我的vue.js set_password:
methods: {
set_password() {
axios.post('/app/reset-password/confirm/', {'password': this.password, 'token': this.token})
.then(response => {
console.log(response)
})
.catch(error => {
console.log(error)
})
}
},
如果我使用RestMan将POST请求发送到http://localhost:8000/app/reset-password/confirm/
以在django服务器上引发异常,例如:我得到的短密码:
{
"password": [
"This password is too short. It must contain at least 8 characters.",
"This password is too common."
]
}
但是在我的vue.js set_password()中,我确实无法获得这些异常。在浏览器控制台中,我得到:
POST http://localhost:8000/app/reset-password/confirm/ 400 (Bad Request)
Error: Request failed with status code 400
at createError (build.js:15685)
at settle (build.js:27186)
at XMLHttpRequest.handleLoad (build.js:15559)
如果我发送了一个很好的密码(不是短密码,等等...),我将在浏览器控制台中“响应”:
{data: {…}, status: 200, statusText: "OK", headers: {…}, config: {…}, …}
但是如何从django服务器获取异常?
答案 0 :(得分:0)
在您的vue.js
中,如果您登录error.response.data
将为您提供完整的错误。