Permalink
Browse files

Handle errors during join on the client.

  • Loading branch information...
1 parent c2f2c2f commit 5a92c9cfda5d98f48e7bbc81d6ba042dcc675471 @scottgonzalez committed Apr 27, 2010
Showing with 20 additions and 13 deletions.
  1. +10 −10 demo/web/js/client.js
  2. +10 −3 demo/web/js/nodechat.js
View
@@ -170,18 +170,18 @@ $(function() {
return false;
}
- $(this).one("ajaxSuccess.login", function() {
- login.unbind("ajaxError.login");
- $("body")
- .removeClass("login")
- .addClass("channel");
- message.focus();
- }).one("ajaxError.login", function() {
- loginError("Nickname in use.");
+ channel.join(nick, {
+ success: function() {
+ $("body")
+ .removeClass("login")
+ .addClass("channel");
+ message.focus();
+ },
+ error: function() {
+ loginError("Nickname in use.");
+ }
});
- channel.join(nick);
-
return false;
});
login.find("input").focus();
View
@@ -66,17 +66,24 @@ $.extend(Channel.prototype, {
});
$.extend(Channel.prototype, {
- join: function(nick) {
+ join: function(nick, options) {
var channel = this;
this.request("/join", {
data: {
nick: nick
},
success: function(data) {
- // TODO: handle errors
+ if (!data) {
+ (options.error || $.noop)();
+ return;
+ }
+
channel.id = data.id;
channel.poll();
- }
+
+ (options.success || $.noop)();
+ },
+ error: options.error || $.noop
});
},

0 comments on commit 5a92c9c

Please sign in to comment.