Skip to content

Commit

Permalink
feat: fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
sjfkai committed Jul 6, 2017
1 parent c896a6c commit 86b0b3b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion grab12306.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ grabStation(global).then(function() {
//时刻表
return grabSchedule(global);
}).then(function() {
var time = moment().subtract(beginTime);
const seconds = moment().unix() - beginTime.unix();
var time = moment().startOf('day').seconds(seconds);

logger.info("所有抓取已完成,共耗时"+time.format("H时mm分ss秒"));
}).catch(logger.error);
Expand Down
9 changes: 8 additions & 1 deletion lib/grab_schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ var grabSchedule = function(global) {
url: url,
strictSSL: false
}).then(function(res) {
var data = JSON.parse(res[1]);
var data;
try {
data = JSON.parse(res[1]);
} catch (error) {
logger.error("request error 将尝试再次抓取 12306的数据为:" + res[1]);
errorList.push(train);
return Promise.resolve();
}
if (!(data.httpstatus && data.httpstatus == 200)) {
logger.error("request error 将尝试再次抓取 12306的数据为:" + res[1]);
errorList.push(train);
Expand Down

0 comments on commit 86b0b3b

Please sign in to comment.