diff --git a/.gitignore b/.gitignore index 2d0d9f8..558ff72 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ auth.js db.js node_modules *.swp +*.log diff --git a/index.js b/index.js old mode 100644 new mode 100755 index 8ea0c74..83466d6 --- a/index.js +++ b/index.js @@ -1,3 +1,5 @@ +#!/usr/bin/env node + require( "./botanss/package" ); require( "./config/global" ); diff --git a/logs/README b/logs/README new file mode 100644 index 0000000..94e7cab --- /dev/null +++ b/logs/README @@ -0,0 +1 @@ +Allow access to www-data diff --git a/notify-term/Notis.js b/notify-term/Notis.js index 1e1d497..a546c0a 100644 --- a/notify-term/Notis.js +++ b/notify-term/Notis.js @@ -12,6 +12,7 @@ class Notis { this.__valid = false; this.__error = null; + this.Retry = 0; try { diff --git a/notify-term/WNSAuth.js b/notify-term/WNSAuth.js index b44a729..f7c70df 100644 --- a/notify-term/WNSAuth.js +++ b/notify-term/WNSAuth.js @@ -115,6 +115,7 @@ class WNSAuth extends EventEmitter Deliver( NotisQ ) { + var _self = this; Model.Tokens .findOne({ name: NotisQ.id }) .exec( ( err, data ) => { @@ -128,6 +129,26 @@ class WNSAuth extends EventEmitter { this.__send( data.token, NotisQ, ( sender, e ) => { Dragonfly.Debug( "Send: " + e.statusCode ); + + if( e.statusCode != 200 ) + { + AuthToken = null; + Dragonfly.Info( "Perhaps access token is expired, retrying ..." ); + + if( NotisQ.Retry < 2 ) + { + _self.once( "AuthComplete", () => { + NotisQ.Retry ++; + _self.Deliver( NotisQ ); + }); + } + else + { + Dragonfly.Info( "Retrying exceeded the limit, dropping the message" ); + } + + _self.Authenticate(); + } } ); } else