-
Notifications
You must be signed in to change notification settings - Fork 982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Faraday::Response::Json
not loaded by default with Faraday 1
#1594
Comments
Hi @jrmhaig this shouldn't be causing issues because you'd normally use the registered symbol to load the middleware rather than the fully qualified class name: Faraday.new(...) do |f|
f.response :json # rather than `f.use Faraday::Response::Json`
end This should work because the If there's any reason why this is actually causing issues I might investigate further, please let me know if the above doesn't work for you or if you have a specific use-case |
Thank you for the quick response. I haven't put together a minimal working example yet so I would hold off doing any further investigation if I were you. I am seeing the issue in this PR - ministryofjustice/laa-court-data-ui#2044 - which updates the |
OK, so it appears that it is the conflict with require 'json_api_client'
require 'faraday_middleware'
module ScienceMuseum
class Base < JsonApiClient::Resource
self.site = 'https://collection.sciencemuseumgroup.org.uk/search'
connection do |conn|
conn.use(
FaradayMiddleware::OAuth2,
'asdf',
token_type: :bearer
)
end
end
class Object < Base
end
class Person < Base
end
class Place < Base
end
end
x = ScienceMuseum::Object.all
pp x OAuth isn't actually required for this particular API but it is enough in this example to repeat the error at the I believe that there is a better way using the |
After reproducing this locally and taking a closer look, I concluded we likely forgot to update the "autoloader". The only "conflict" now is on the registered This would still cause issues in Possible workarounds here would be:
Neither of the above look good though, because it would require either the gem authors or the user to know about this particular setup 😞 It would take some additional time and tinkering, but that should be possible in theory 🤔 |
We've now released a new version of @jrmhaig if you could give it a try in your project, it would be greatly appreciated ❤️ I'm gonna close this issue now but please let me know if you manage to try it out! |
Thanks. That's fantastic. I have upgraded |
Basic Info
Issue description
Faraday::Response::Json
is not loaded by default. This class was created in #1400 specifically to allow the two versions to be used interchangeably, so that gems that use Faraday can support both. However, this class is loaded automatically with version 2 so its use is not exactly interchangeable.Steps to reproduce
For reference, with Faraday 2:
The text was updated successfully, but these errors were encountered: