GraphErrorChecker#response_hash returns nil causing gem to crash
nasaabg opened this issue · comments
This is a Koala bug/issue problem.
Hi!
At @zendesk we use your gem in version 3.0.0
and I come across that issue on our Production ENV.
For some reason we have been notified about an error:
NoMethodError
undefined method `[]' for nil:NilClass
in koala/api/graph_error_checker.rb in base_error_info at line 57
I did a little of debugging and seems that https://github.com/arsduo/koala/blob/master/lib/koala/api/graph_error_checker.rb#L60 returns nil
in some cases while I assume we expect #response_hash
always return Hash (empty or not).
Cases like those would return sth different than Hash and would cause gem to crash:
- JSON.parse('true') ==> true
- JSON.parse('null') ==>
nil
(our case) - JSON.parse('false') ==> false
I have a proposal to fix it, but I can not push
my branch to the repository and open PR :(
So here it is:
def response_hash
# Normally, we start with the response body. If it isn't valid JSON, we start with an empty
# hash and fill it with error data.
@response_hash ||= begin
response_body = JSON.parse(body)
response_body.is_a?(Hash) ? response_body : {}
rescue JSON::ParserError
{}
end
end
NOTE: Looks like we are using fork
but this issues is still valid
released as 3.5.0