0

I am trying to determine how to get SignalR to properly raise the fail method of a jQuery deferred.

Currently I am achieving this as follows"

public void JoinChat(string username) 
{
  var user = userRepo.getUser(username);

  if(user == null)
  { 
    throw new Exception('user doesn't exist');
  }

  //set up user here

}

then in my js for the client I am doing this

$.connection.myHub.joinChat(this.username)
                  .done(//success callback)
                  .fail(//fail callback);

I feel that having the Hub generating an exception to achieve the failure on the deferred is not an ideal way to do this, but I haven't been able to find anyway to get a proper fail call back generated.

I would like to avoid having a return code since there are methods where I am returning actual useful information from the hub (the join method is just a simple example).

Is there a preferred method of invoking the fail condition for the jQuery deferred?

msarchet
  • 15,104
  • 2
  • 43
  • 66

1 Answers1

1

It's the only case where the fall callback will be called. When there's a failure (i.e. an exception).

davidfowl
  • 37,120
  • 7
  • 93
  • 103
  • k makes sense, I just wanted to make sure that there wasn't soemthing in SignalR that would handle it less abruptly – msarchet Jan 19 '13 at 22:45