HTTP Status code 204 no content #2017

Closed
Pindar opened this Issue Dec 24, 2012 · 10 comments

Comments

Projects
None yet
5 participants

Pindar commented Dec 24, 2012

I recognized that currently backbone.js tries to update the model also in case of no content (http status code 204). So the validation and all update functions will be called but without data it finally returns an error.

Is this behavior desired or should backbone recognize the special status code?

Collaborator

caseywebdev commented Dec 24, 2012

This is up to your parse function.

parse: (resp, options) {
  if (options.xhr.status === 204) return this.attributes;
  return resp;
}

Or however you want to deal with it.

Contributor

philfreo commented Dec 24, 2012

It seems like a valid usecase for Backbone to handle this correctly (it already handles 500 error codes differently, for example)

Collaborator

tgriesser commented Dec 24, 2012

Wouldn't the handling of status codes be a jQuery issue? @Pindar - where are you running into the error, and what version of Backbone and jQuery are you using?

Pindar commented Dec 25, 2012

@caseywebdev: your suggestion should be working, but I also agree with @philfreo that this could be a backbone task.

@tgriesser It's in the save function (line 464, https://github.com/documentcloud/backbone/blob/master/backbone.js#L464). The set function tries to set an empty string and therefore it returns false. I will write a little test in the next days.
jQuery works right at this point because it calls the success callback. I think that either backbone should handle this special case or the user have to copy all attributes like in @caseywebdev suggestion.

jQuery: 1.8.3
backbone: 0.9.9

Collaborator

tgriesser commented Dec 26, 2012

@Pindar this should be taken care of by #2024 - let me know if that works for you. Thanks for pointing out this issue!

tgriesser closed this Dec 26, 2012

Pindar commented Jan 3, 2013

@tgriesser Thx for the change! I tried to test it with the new master version (a93ed04) but now I have some trouble with other changes: #2064 . Maybe you can answer my new question?

Pindar commented Jan 7, 2013

@tgriesser I finally tested your changes and it works for me. Thx!

ryanmt commented Jan 8, 2015

.fetch({success: testSuccess})

and

testSuccess: function(collection, response) {
  console.log(response) // => null 
}

This happens when the response is 204. This seems like something is really wrong. Should I open a ticket?

Pindar commented Jan 8, 2015

I don't get the problem:

The 204 response MUST NOT include a message-body, and thus is always terminated by the first empty line after the header fields.
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

ryanmt commented Jan 8, 2015

When you get the response from a 400 error code in the error callback, it is an object with a status key. I expected the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment