theganyo / usergrid_iron

A simple, low-level Ruby SDK to Apigee's App Services (aka Usergrid) REST API with minimal dependencies.
Other
8 stars 10 forks source link

Handle server exceptions #2

Open theganyo opened 11 years ago

theganyo commented 11 years ago

This shouldn't happen:

/Users/sganyo/.rvm/gems/ruby-2.0.0-p0/gems/ugc-0.9.6/bin/ugc:76:in `block in ': undefined method `data' for nil:NilClass (NoMethodError)
    from /Users/sganyo/.rvm/gems/ruby-2.0.0-p0/gems/gli-2.5.0/lib/gli/app_support.rb:246:in `call'
    from /Users/sganyo/.rvm/gems/ruby-2.0.0-p0/gems/gli-2.5.0/lib/gli/app_support.rb:246:in `regular_error_handling?'
    from /Users/sganyo/.rvm/gems/ruby-2.0.0-p0/gems/gli-2.5.0/lib/gli/app_support.rb:189:in `handle_exception'
    from /Users/sganyo/.rvm/gems/ruby-2.0.0-p0/gems/gli-2.5.0/lib/gli/app_support.rb:71:in `rescue in run'
    from /Users/sganyo/.rvm/gems/ruby-2.0.0-p0/gems/gli-2.5.0/lib/gli/app_support.rb:54:in `run'
    from /Users/sganyo/.rvm/gems/ruby-2.0.0-p0/gems/ugc-0.9.6/bin/ugc:86:in `'
    from /Users/sganyo/.rvm/gems/ruby-2.0.0-p0/bin/ugc:23:in `load'
    from /Users/sganyo/.rvm/gems/ruby-2.0.0-p0/bin/ugc:23:in `
' from /Users/sganyo/.rvm/gems/ruby-2.0.0-p0/bin/ruby_noexec_wrapper:14:in `eval' from /Users/sganyo/.rvm/gems/ruby-2.0.0-p0/bin/ruby_noexec_wrapper:14:in `
'

when a response like this is processed:

# => 400 BadRequest | application/json 160 bytes
D, [2013-08-01T09:50:08.508096 #51039] DEBUG -- : response.body = {"error":"index_out_of_bounds","timestamp":1375375808506,"duration":0,"exception":"java.lang.IndexOutOfBoundsException","error_description":"Index: 3, Size: 3"}
Index: 3, Size: 3
hayesmp commented 11 years ago

Wow. This really sucks. It would have been nice to just capture the status code and output my own error.

My hack solution:

begin
    organization.create_application form.app_name
    status = "success"
rescue
    status = "failure or application already exists"
end
theganyo commented 11 years ago

Actually, the code you have is correct and expected. usergrid_iron wraps the restclient gem which has the default behavior of returning "the response itself for code in 200..206, redirection for 301, 302 and 307 in get and head cases, redirection for 303 and an exception in other cases."

hayesmp commented 11 years ago

Is there a way to disable the debug output for each usergrid command?

theganyo commented 11 years ago

Try something like: Usergrid::LOG.level = Logger::WARN

hayesmp commented 11 years ago

Sweet. Thanks man! :+1:

theganyo commented 11 years ago

No problem!

hayesmp commented 11 years ago

Hey, sorry to throw this into this issue thread, but why are there two different independently maintained usergrid iOS SDKs?

theganyo commented 11 years ago

I believe just legacy. But everything is being moved over to Apache now anyway... so that will be the official repo of all things Usergrid. :)