Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Empty server response causes "Unexpected end of input" exception #57

merged 1 commit into from

3 participants


This adds a simple check to the data length in addition to the existence of data when parsing JSON. Rails PUT operations return an empty string, which causes this exception.


Isn't this more of a rails bug?

No, it's not a rails bug. It's a bug in the restler JSON-handling code that is triggered by interacting with rails rest services. The restler code blows up if data is not null, but contains no useful data, so this is just a trivial fix to prevent that

Realistically, this should be left to the JSON decoder itself to determine if valid JSON was provided, but that obviously doesn't happen nicely. Another option would be to put the JSON.parse in a try/catch, which would handle a wider array of possible deserialization issues.


The latter approach would be better. I'll merge this fix in for now. Wrapping with a try/catch would be good when better error handling is implemented (in the 0.3.x branch).

@ayoung ayoung merged commit 39d1dae into danwrong:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1  lib/restler.js
2  lib/restler.js
@@ -213,7 +213,7 @@ var parsers = {
json: function(data, callback) {
- callback(data && JSON.parse(data));
+ callback(data && data.length > 1 && JSON.parse(data));
Something went wrong with that request. Please try again.