Vue-resource: handling in case of status code 204

Created on 2 May 2017  路  8Comments  路  Source: pagekit/vue-resource

Reproduction Link


await Post('my method name', JSON.stringify(my param))
.then(response => {
console.log('response: ', response)
if (Helper.IsValid(response, true)) {
// code need to fire
}
}, response => {
console.log('error response: ', response)
})

Steps to reproduce

Chrome 57 / Windows 10 Pro

What is Expected?

In case of http return code 204 it should fire success handler of vue-resource.

What is actually happening?

In case of http return code 204 it should fire success handler but it's firing error handler of vue-resource..

Most helpful comment

I'm also having trouble with the 201 status code being rejected. This is particularly difficult to handle when using a try catch statement. Anybody know why it would be rejected?

try {
  this.hasPendingRequest();
  const request = await this.$http.post(uri, data);

  // handle good response
} catch (e) {
  // handle bad response - 201 responses are also caught
} finally {
  this.clearPendingRequest();
}

All 8 comments

couldn't you just check it with response.ok?

I'm also having trouble with the 201 status code being rejected. This is particularly difficult to handle when using a try catch statement. Anybody know why it would be rejected?

try {
  this.hasPendingRequest();
  const request = await this.$http.post(uri, data);

  // handle good response
} catch (e) {
  // handle bad response - 201 responses are also caught
} finally {
  this.clearPendingRequest();
}

Hi @ivanwitzke ,
no matter it always goes to error section so you can not check it with "response.ok", for the time being i have changed it with "axios" plugin.

@KyleNeedham not sure if 201 is the root cause of the rejection.

Made a small example which seems to work fine.

https://jsfiddle.net/cv9xon73/

Hi @herrmannplatz ,

Service in the jsfiddle returning 403
image

Not sure why you get a 403. You might wanna check the error message in detail.

bildschirmfoto 2017-08-23 um 09 20 55

May be issue when using with vue application :)

@herrmannplatz You're right I just updated the endpoint to use a 201 again and it works fine. Must have been something else causing the error, also tried a 204 and that worked as well.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

V-Tom picture V-Tom  路  3Comments

ramstein74 picture ramstein74  路  3Comments

briward picture briward  路  4Comments

EmilMoe picture EmilMoe  路  5Comments

mikeyao picture mikeyao  路  6Comments