From 5b6afd299889a754a2be220e2499b22bbc68b291 Mon Sep 17 00:00:00 2001 From: Andy Chen Date: Fri, 25 Aug 2017 17:47:23 +0800 Subject: [PATCH] fix potential bug when crawler got error --- .vscode/launch.json | 8 +++++++- ticket.js | 6 +++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 87dafd2..6cfa390 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -7,8 +7,14 @@ { "type": "node", "request": "launch", - "name": "Launch Program", + "name": "Launch File", "program": "${file}" + }, + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "program": "${workspaceRoot}/server.js" } ] } \ No newline at end of file diff --git a/ticket.js b/ticket.js index 8137c4e..f137705 100644 --- a/ticket.js +++ b/ticket.js @@ -19,7 +19,7 @@ const getTicketStatus = (sportsId) => { return new Promise(async (resolve, reject) => { try { const $ = await getCheerio$(`${rootUrl}/schedule/17_TPE_${sportsId}`) - const promises = Array.from($('#schedule-info tr:has(button)').map(async (index, tr) => { + const results = Array.from($('#schedule-info tr:has(button)').map((index, tr) => { const $tr = $(tr); const $tds = $tr.find('td') const ticketUrl = rootUrl + $tr.find('button').attr('onclick').split('\'')[1]; @@ -31,11 +31,11 @@ const getTicketStatus = (sportsId) => { url: ticketUrl } })); - const results = await Promise.all(promises); resolve(results); } catch (err) { - console.error(err) + console.error(err); + resolve([]); } }) }