M
M
Mike2019-07-10 20:29:22
Vue.js
Mike, 2019-07-10 20:29:22

How to get exceptions from django-rest in vue.js?

I am using django-rest-passwordreset to recover a forgotten password.
In Vue.js I have a method to set a new password. It works, but you need to get exceptions if the password is too short or too simple, etc..

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)
        })
    }
},

If I send a POST request to http://localhost:8000/app/reset-password/confirm/which should throw exceptions on the server (for example, a short password) via RestMan, I get
{
    "password": [
        "This password is too short. It must contain at least 8 characters.",
        "This password is too common."
    ]
}

But in Vue.js I can't/don't know how to do it. In the browser, in the console I get:
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)

If I send a valid password, then I get the contents of the response like this:
{data: {…}, status: 200, statusText: "OK", headers: {…}, config: {…}, …}

But how can I get exceptions from the server?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Suha, 2019-07-10
@andreysuha

In catch
console.log(error.response)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question