diff options
| author | Misko Hevery | 2011-08-31 10:01:40 -0700 |
|---|---|---|
| committer | Igor Minar | 2011-08-31 14:34:56 -0700 |
| commit | c763b009ac16cefba28a4bfa84cd6c98e9d6a620 (patch) | |
| tree | 3dcf5ca55714b93d7be09988c403cdcfadd76730 | |
| parent | e5da0c956b5bc6f2da835f4307b2322de0785a9b (diff) | |
| download | angular.js-c763b009ac16cefba28a4bfa84cd6c98e9d6a620.tar.bz2 | |
feat(gdocs.js): output usefull error messages when not logged in.
| -rwxr-xr-x | gdocs.js | 41 |
1 files changed, 31 insertions, 10 deletions
@@ -54,7 +54,7 @@ function fetch(collection, url){ if (title.match(/\.ngdoc$/)) { var exportUrl = entry.match(/<content type='text\/html' src='(.*?)'\/>/)[1]; download(collection, title, exportUrl); - } + }; }); } ); @@ -136,7 +136,13 @@ function login(username, password){ } function getAuthToken(){ - return fs.readFileSync('tmp/gdocs.auth'); + var pwdFile = 'tmp/gdocs.auth'; + try { + fs.statSync(pwdFile); + return fs.readFileSync(pwdFile); + } catch (e) { + console.log('Please log in first...'); + } } function request(method, url, options, response) { @@ -147,14 +153,29 @@ function request(method, url, options, response) { path: url[3], method: method }, function(res){ - var data = []; - res.setEncoding('utf8'); - res.on('end', function(){ - response(data.join('')); - }); - res.on('data', function (chunk) { - data.push(chunk); - }); + switch (res.statusCode) { + case 200: { + var data = []; + res.setEncoding('utf8'); + res.on('end', function(){ + response(data.join('')); + }); + res.on('data', function (chunk) { + data.push(chunk); + }); + res.on('error', function(e){ + console.log(e); + }); + break; + } + case 401: { + console.log('Eror: Login credentials expired! Please login.'); + break; + } + default: { + console.log(res); + } + } }); for(var header in options.headers) { request.setHeader(header, options.headers[header]); |
