adelevie / parse-ruby-client

A simple Ruby client for the parse.com REST API
MIT License
415 stars 137 forks source link

A JSON text must at least contain two octets! #101

Open ddavtian opened 11 years ago

ddavtian commented 11 years ago

I think this might be an issue in the JSON parser?

    [2013-07-31T21:32:05.718626 #9653]  WARN -- : Retrying Parse Error #<JSON::ParserError: A JSON text must at least contain two octets!> on request /1/users nil response #<Patron::Response @status_line='HTTP/1.1 502 BAD_GATEWAY'>

/Users/ddavtian/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/json/common.rb:155:in `initialize': A JSON text must at least contain two octets! (JSON::ParserError)
from /Users/ddavtian/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/json/common.rb:155:in `new'
from /Users/ddavtian/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/json/common.rb:155:in `parse'
from /Users/ddavtian/.rvm/gems/ruby-2.0.0-p0/gems/parse-ruby-client-0.1.15/lib/parse/client.rb:102:in `request'
from /Users/ddavtian/.rvm/gems/ruby-2.0.0-p0/gems/parse-ruby-client-0.1.15/lib/parse/query.rb:127:in `get'
from new_facebook_user_notify.rb:56:in `compareFacebookFriendsToParse'
from new_facebook_user_notify.rb:99:in `<main>'
ericcj commented 11 years ago

this is a server error from parse as per the 502 response code. it was retried so hopefully it succeeded? in any case this isn't a client bug

henrik commented 10 years ago

"A JSON text must at least contain two octets!" is tech talk for "The JSON library got an empty string but expected some JSON, at the very least an {}".

It might be helpful if the client would encapsulate this and instead raise an error something like Parse::ServerError.

adelevie commented 10 years ago

I'm fine with this. Wanna send a PR?

ericcj commented 10 years ago

this one is actually logging of a retry, but it would be indeed be re-raised as JSON::ParserError if retries were exhausted. it would probably be preferable to encapsulate all server errors (5xx, timeout, patron, whatever) under Parse::ServerError as long as it captured the cause

henrik commented 10 years ago

I'm afraid I don't have the time to make a pull request at the moment. Possibly later, if we do a "handle Parse errors gracefully" sprint.

rails-webmaster commented 9 years ago

Hello,

I have the same issue as you had. Here is the code base I am running on.

params = {:first_name => "John", :last_name => "Smith"}

uri = URI.parse(make_uri("person/" + id.to_s)) Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https', :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|

request = Net::HTTP::Patch.new(uri.request_uri)
request.add_field('Content-Type', 'application/json')
request.body = JSON.dump(params)

@response = http.request request # Net::HTTPResponse object

end

JSON.parse @response.body

I hope you would like to help me with any solution.

Best regards,

John