Skip to content
Browse files

error handling for postToTwitter

  • Loading branch information...
1 parent 7d93b1a commit 440d040045e7a931c46ca295b0b4fca2f83d8392 @koyachi committed Mar 2, 2011
Showing with 21 additions and 5 deletions.
  1. +0 −1 server.js
  2. +21 −4 static/js/client.js
View
1 server.js
@@ -167,7 +167,6 @@ conf.initConfig(function(err){
}
console.log('Post to Twitter: ' + message[msg_id]);
postToTwitter(req, res, message[msg_id]);
- res.send(message[msg_id]);
} else {
res.redirect('/');
}
View
25 static/js/client.js
@@ -63,6 +63,11 @@ function stopAnimation(e){
this.animationCount = 0;
}
}
+function displayStaticImage(image, e) {
+ var elm = document.getElementById(this.elmId);
+ if (this.fixPosition) this.fixPosition(e);
+ elm.src = "/image/" + image + ".png";
+}
var Screen = {
status: '',
@@ -77,6 +82,8 @@ var Screen = {
Screen.startSendingAnimation = _.bind(startAnimation, Screen, ['screen_post1', 'screen_post2']);
Screen.startOkAnimation = _.bind(startAnimation, Screen, ['screen_ok1', 'screen_ok2']);
Screen.stopAnimation = _.bind(stopAnimation, Screen, null);
+Screen.displayError = _.bind(displayStaticImage, Screen, 'screen_ng');
+Screen.displayBlank = _.bind(displayStaticImage, Screen, 'screen_blank');
var Touch = {
status: '',
@@ -159,10 +166,20 @@ function buttonClicked(text){
if (xhr.readyState === 4) {
var data = xhr.responseText;
Screen.stopAnimation();
- Screen.startOkAnimation();
- setTimeout(function(){
- Screen.stopAnimation();
- }, 4000);
+ if (data == 'ok') {
+ Screen.startOkAnimation();
+ setTimeout(function(){
+ Screen.stopAnimation();
+ }, 4000);
+ }
+ else {
+ // error
+ Screen.displayError();
+ window.alert('ERROR:postToTwitter: ' + data);
+ setTimeout(function(){
+ Screen.displayBlank();
+ }, 4000);
+ }
// window.alert('done');
}
}

0 comments on commit 440d040

Please sign in to comment.
Something went wrong with that request. Please try again.