orlaqp
orlaqp

Reputation: 622

Meteor: I can't get the onError callback to fire when throwing error from subscription

Ok this is the server code where I publish my data if the current user have access to see it

# server publish
Meteor.publish 'clients', (locationId) ->
if SecurityContext.canAccessLocation @userId, locationId
    @ready()
    @error new Meteor.Error('unauthorized', 'You do not have access to this location')
    return

ClientManagement.Collections.Clients.find({ locationId: locationId }, { sort: firstName: 1 })

This is a section of my iron-router's controller where I wait for my data to come back but my callbacks for onReady or onError are never called

# iron route controller
waitOn: ->
    Meteor.subscribe 'clients', Session.get 'selectedLocationId',
        onReady: ->
            debugger
        onError: (error) ->
            debugger
            AppHelper.logger.error error.reason

What am I doing wrong here? Any suggestions? I also tried something similar outside of iron-router just to double check it was not related to the router.

I did this on the client side:

Meteor.startup () ->

  Tracker.autorun ->
      Meteor.subscribe 'clients', Session.get 'selectedLocationId',
          onReady: ->
              debugger
          onError: (error) ->
              debugger
              AppHelper.logger.error error.reason

Again nothing my callbacks are never called ... any ideas??

Thanks in advance!

Upvotes: 0

Views: 197

Answers (1)

David Weldon
David Weldon

Reputation: 64312

This looks like a coffeescript mistake. The transpiler doesn't know if you mean to include the callback object as an argument to subscribe or to get. It chooses the latter, but you want the former. Try something like this instead:

Meteor.subscribe 'clients', Session.get('selectedLocationId'),
  onReady: ->
    console.log 'ready!'
  onError: ->
    console.log 'error!'

Upvotes: 2

Related Questions