2

I am trying to catch error in

this.$http.post('http://127.0.0.1:8000/api/address/store',address_data,{headers: {'Authorization': 'Bearer ' + this.$auth.getToken()}}).then(response => {
                    if(response.status == 422) {
                        console.log('hello')
                        console.log(response)
                    }
            })

But I can't catch in this way. Thanks.

abu abu
  • 6,599
  • 19
  • 74
  • 131
  • 1
    This answer on stackoverflow will clear your doubts - https://stackoverflow.com/questions/43092995/vuejs-http-request-error-500-handling – Meet Zaveri Mar 13 '18 at 05:26

1 Answers1

8

It looks like you are using vue-resource to make your ajax requests. I've only used axios but glancing at the docs for vue-resource looks like your error callback is the second argument for .then()

Example

this.$http.post('/someUrl', [body], [config]).then(successCallback, errorCallback);

Try this in your code

this.$http.post('http://127.0.0.1:8000/api/address/store',address_data,
  {headers: {'Authorization': 'Bearer ' + this.$auth.getToken()}})
  .then(response => {
    // success
  }, response => {
    //error
    if(response.status == 422) {
      console.log('hello')
      console.log(response)
    }
  })

Here is link to the docs: https://github.com/pagekit/vue-resource

Community
  • 1
  • 1
doublea
  • 447
  • 1
  • 4
  • 11