[Vuejs]-How to respond the server responded with a status of 404

1👍

I guess by now it is not possible to give you a "solution" as you’re not giving enough information to solve your problem.

Except if you misspelled the path to your API (/api/v1/users/) I think the problem actually come from your API. Either your "rewrite rule" in "urls.py" or file alike, or the function that it calls is wrong. Check syntax on docs.djangoproject.com.

And, passing by, you’re "strange error" is just caused by your loop on the string error.response.data, so I would suggest to just push the data without loop, or to use the following:

.catch(error => {
  if (error.response) {
    if (typeof error.response.data === "String") {
      this.errors.push(error.response.data)
    } else {
      for (const property in error.response.data){
        this.errors.push(`${property}: ${error.response.data[property]}`)
      }
    }
  } else if (error.message) {
    this.errors.push('Something went wrong. Please try again!')
  }
})

In conclusion, if you can’t find the problem in your API or in a misspelling mistake, you can still add your django content in your question, to make it more complete.

0👍

It seems he API has not been implemented, or you are not calling the correct endpoint in django.

Thus django is simply returning the default 404 html page as a response; which is a string or text/html format. and your error block:

for (const property in error.response.data){
  this.errors.push(`${property}: ${error.response.data[property]}`)
}

is simply parsing it out as a array of characters in the format <index>: <char> as using for .. in with an array will give you the indexes of the elements in array

Leave a comment