Only instantiate OAuth2::Error if raise_errors option is true
Don't raise exceptions if we've set the raise_errors client option to false.
We've run into 3rd party APIs that say they are returning JSON, but in some rare error cases they do not. When that happens the OAuth2 Library causes an exception to be raised even if we've disabled the raise_errors client option. In these cases we want to handle the error ourselves and doing so requires the response. But if a parsing exception is raised in the OAuth2 gem we don't get back the response. This has caused us to monkey patch the OAuth2 gem and we'd rather not do that.
The issue is that OAuth2::Client
instantiates an OAuth2::Error
object no matter the value of raise_errors. And the OAuth2::Error
object calls .parsed
on the response. So if you have an invalid response for the content type, a parser error is raised from that content type's parser.