jnunemaker / jnunemaker/httparty
HTTParty::Response fakes nil
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 5.9k
- Forks
- 973
- Avg merge
- 1h 59m
- Merged PRs (30d)
- 1
Description
HTTParty::Response sometimes looks nil but isn't. This makes for some interesting consequences and strange code in order to deal with them:
[1] pry(#Salesforce::Rest)> response
=> nil
[2] pry(#Salesforce::Rest)> response.code
=> 413
[4] pry(#Salesforce::Rest)> response.class
=> HTTParty::Response
[11] pry(#Salesforce::Rest)> response == nil
=> false
[12] pry(#Salesforce::Rest)> response.nil?
=> true
[13] pry(#Salesforce::Rest)> !!response
=> true
So in my code I have:
if !((200..299).include?(response.code))
if response.nil?
raise "SF ERROR #{response.code}" # fake nil, not a bug
else
raise "SF ERROR '#{response.message}': #{response.first['message']}"
end
end
As I see it there are two problems:
- Response#inspect returns 'nil'
- Response#nil? somehow returns true
I don't know why (2) happens, something to do with Ruby's internal implementation of .nil?, which is defined in Object.
Perhaps you can suggest an improvement for my error detecting code.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the reported behavior with HTTParty::Response, then inspect its inspect and nil? behavior. The issue does not name files or tests; done should mean establishing the intended nil semantics and adding coverage for the observed response behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- backend, networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100