Closed utx0 closed 12 years ago
It's returned in the body because the httpstat.us website puts it in the body (i.e. this isn't BW doing that).
However, I'd think the error_message should contain "Bad Gateway". I'll investigate when I get a chance.
Ok, it looks like the error_message field is actually for iOS's URL loading error codes (e.g. "can't find host", "DNS lookup failed", "bad url", etc.) For example, using an invalid url with a typo: (I added the rescue clauses, otherwise it crashes trying to convert nil using to_str
)
BW::HTTP.post("http://httpstat.uz/502") do |response|
puts "response = #{response}"
puts "response.body = #{response.body.to_str rescue ''}"
puts "response.error_message = #{response.error_message}"
puts "response.status_code = #{response.status_code.to_s rescue ''}"
puts "response ok = #{response.ok?}"
end
gives you:
response = #<BubbleWrap::HTTP::Response:146317216 - url: , body: , headers: , status code: , error message: A server with the specified hostname could not be found. >
2012-09-07 11:15:12.098 gesture[23238:c07] http.rb:372:in `call_delegator_with_response': undefined method `to_str' for nil:NilClass (NoMethodError)
from http.rb:178:in `connection:didFailWithError:'
response.body =
response.error_message = A server with the specified hostname could not be found.
response.status_code =
response ok = false
I think instead of making error_message
mean multiple things, we should add something like status_description
(we can use NSHTTPURLResponse.localizedStringForStatusCode(...)
to get it).
You can now get status descriptions:
puts "response.status_code = #{response.status_code.to_s}"
puts "response.status_description = #{response.status_description}"
response.status_code = 502
response.status_description = bad gateway
I think this is a bug in BW.....
I have a services that returns an error message and status code like the working example I have setup below. The problem I am having is that the response.error_message is not populated with the error message that the services is returning. However its returned in the body?
Here is the out put I am getting:
I have tried to workout if the error message needs to be past back in any special format, but am currently unsure? Please advise if this is the case. Thanks heaps. Luke