mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-05 21:54:42 +00:00
feat(gdocs.js): output usefull error messages when not logged in.
This commit is contained in:
parent
e5da0c956b
commit
c763b009ac
1 changed files with 31 additions and 10 deletions
41
gdocs.js
41
gdocs.js
|
|
@ -54,7 +54,7 @@ function fetch(collection, url){
|
||||||
if (title.match(/\.ngdoc$/)) {
|
if (title.match(/\.ngdoc$/)) {
|
||||||
var exportUrl = entry.match(/<content type='text\/html' src='(.*?)'\/>/)[1];
|
var exportUrl = entry.match(/<content type='text\/html' src='(.*?)'\/>/)[1];
|
||||||
download(collection, title, exportUrl);
|
download(collection, title, exportUrl);
|
||||||
}
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
@ -136,7 +136,13 @@ function login(username, password){
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAuthToken(){
|
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) {
|
function request(method, url, options, response) {
|
||||||
|
|
@ -147,14 +153,29 @@ function request(method, url, options, response) {
|
||||||
path: url[3],
|
path: url[3],
|
||||||
method: method
|
method: method
|
||||||
}, function(res){
|
}, function(res){
|
||||||
var data = [];
|
switch (res.statusCode) {
|
||||||
res.setEncoding('utf8');
|
case 200: {
|
||||||
res.on('end', function(){
|
var data = [];
|
||||||
response(data.join(''));
|
res.setEncoding('utf8');
|
||||||
});
|
res.on('end', function(){
|
||||||
res.on('data', function (chunk) {
|
response(data.join(''));
|
||||||
data.push(chunk);
|
});
|
||||||
});
|
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) {
|
for(var header in options.headers) {
|
||||||
request.setHeader(header, options.headers[header]);
|
request.setHeader(header, options.headers[header]);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue