Avoid reparsing a response body

Created by: nbibler

The oauth2 v2 release removed the rescue catch-all when parsing failed. This exposed a possible issue where someone overriding or extending the Faraday connection middleware stack may parse response bodies ahead of the packaged middleware in this library. In that case, this library attempts to re-parse an already-parsed body, thereby throwing various exceptions (TypeError: no implicit conversion of Hash into String, for example).

Faraday doesn't provide a standard interface to determine whether or not a response has already been parsed. Instead, it relies on middleware developers performing cursory checks of the object type (generally, if the body responds to to_str then it's probably a string, and it's probably not yet parsed).

This change adds that cursory check to make sure the response body is still string-like before attempting to parse it into Ruby objects.

Merge request reports

Loading