jashkenas / backbone

Give your JS App some Backbone with Models, Views, Collections, and Events
http://backbonejs.org
MIT License
28.1k stars 5.39k forks source link

HTTP Status code 204 no content #2017

Closed Pindar closed 11 years ago

Pindar commented 11 years ago

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?

caseywebdev commented 11 years ago

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.

philfreo commented 11 years ago

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

tgriesser commented 11 years ago

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 11 years ago

@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

tgriesser commented 11 years ago

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

Pindar commented 11 years ago

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

Pindar commented 11 years ago

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

ryanmt commented 9 years ago

.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 9 years ago

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 9 years ago

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.