Fix for circular reference exceptions between Error and Response classes

Created by: jhmoore

This is to replace https://github.com/oauth-xx/oauth2/pull/201. This is a breaking change! It removes the ability to call .error from an OAuth2::Response object.

Also, adding some test coverage and fixing a potential 500 if a response is encountered with no headers. The Response class was calling response.headers.values_at without checking to see if response.headers returned a valid thing, and also there were no tests for #content_type.

As an aside, the exception referenced in that older pull request only is a thing in older versions of Rails. The current version of ActiveSupport JSON encoding says:

"The JSON encoder in Rails 4.1 no longer offers protection from circular references. " \
"You are seeing this warning because you are rescuing from (or otherwise referencing) " \
"ActiveSupport::Encoding::CircularReferenceError. In the future, this error will be " \
"removed from Rails. You should remove these rescue blocks from your code and ensure " \
"that your data structures are free of circular references so they can be properly " \
"serialized into JSON.\n\n" \
"For example, the following Hash contains a circular reference to itself:\n" \
"   h = {}\n" \
"   h['circular'] = h\n" \
"In this case, calling h.to_json would not work properly."

It is likely not ideal to raise stack level too deep levels either, but from a practical testing standpoint it is not a good idea to detect the presence of that old error.

Merge request reports

Loading
Loading