vue-resource icon indicating copy to clipboard operation
vue-resource copied to clipboard

handling in case of status code 204

Open SiddiquiImran opened this issue 8 years ago • 8 comments

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..

SiddiquiImran avatar May 02 '17 07:05 SiddiquiImran

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

ivanwitzke avatar May 20 '17 03:05 ivanwitzke

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();
}

KyleNeedham avatar Jul 28 '17 19:07 KyleNeedham

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.

SiddiquiImran avatar Jul 31 '17 05:07 SiddiquiImran

@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/

herrmannplatz avatar Aug 22 '17 19:08 herrmannplatz

Hi @herrmannplatz ,

Service in the jsfiddle returning 403 image

SiddiquiImran avatar Aug 23 '17 05:08 SiddiquiImran

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

bildschirmfoto 2017-08-23 um 09 20 55

herrmannplatz avatar Aug 23 '17 07:08 herrmannplatz

May be issue when using with vue application :)

SiddiquiImran avatar Aug 23 '17 08:08 SiddiquiImran

@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.

KyleNeedham avatar Aug 23 '17 09:08 KyleNeedham