Skip to content
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

Requesting channel_info without info: raises an error from the previous request #193

Open
rmosolgo opened this issue Sep 3, 2024 · 0 comments

Comments

@rmosolgo
Copy link

rmosolgo commented Sep 3, 2024

Hi! I'm working on a custom dashboard for GraphQL subscriptions which are backed by Pusher. My dashboard shows information about the state of the GraphQL system (like query string, variables, query context, etc) and information about the underlying transport system -- Pusher in this case.

To improve this dashboard, I want to be able to count subscribers on a Pusher channel ... but I don't know if the manager of the Pusher app has turned on subscription counting yet.

I thought I would just try -- I could request channel_info(channel, info: "subscription_count"), and if that raises a Pusher::Error, then I would re-fetch without info: and only display :occupied from the response. But, I found that my second request to channel_info raised the same error (Bad request: Cannot retrieve the subscription count because subscription counting is not enabled), even though it was called without an info: option. I tried info: nil and info: "", but neither of those made it work.

Here's a small replication script of this issue:

require 'pusher'

# this app doesn't have subscription_count turned on yet:
pusher = Pusher::Client.new(
  app_id: "my-app-id",
  key: "my-app-key",
  secret: "my-app-secret",
  cluster: 'us2',
  use_tls: true
)


begin
  pusher.channel_info("abcdef", info: "subscription_count")
rescue Pusher::Error => err
  puts "Encountered an error: #{err.message.inspect}"
end

pusher.channel_info("abcdef")

When I run that script, it rescues the first error, but the second .channel_info call raises another error:

$ ruby pusher_test.rb
Encountered an error: "Bad request: Cannot retrieve the subscription count because subscription counting is not enabled"
/Users/rmosolgo/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/pusher-2.0.3/lib/pusher/request.rb:89:in `handle_response': Bad request: Cannot retrieve the subscription count because subscription counting is not enabled (Pusher::Error)
	from /Users/rmosolgo/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/pusher-2.0.3/lib/pusher/request.rb:39:in `send_sync'
	from /Users/rmosolgo/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/pusher-2.0.3/lib/pusher/resource.rb:9:in `get'
	from /Users/rmosolgo/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/pusher-2.0.3/lib/pusher/client.rb:168:in `get'
	from /Users/rmosolgo/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/pusher-2.0.3/lib/pusher/client.rb:255:in `channel_info'
	from pusher_test.rb:18:in `<main>'

Is there a way to either:

  • Handle this error such that later .channel_info calls succeed?
  • Or, detect whether the current app has subscription_count turned on?

Thanks so much for taking a look! Let me know if there's anything else I can do on my side to help with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant