diff options
author | Noah Loomans <noahloomans@gmail.com> | 2017-09-06 18:37:42 +0200 |
---|---|---|
committer | Noah Loomans <noahloomans@gmail.com> | 2017-09-06 18:37:42 +0200 |
commit | 702794c8feab387772a8d9913df847c55e8842d5 (patch) | |
tree | f2ff287385c227cbde3b56fd754fb46991b27e08 | |
parent | 4cab46700720f4787d958a258be43e042f2c65e7 (diff) |
Improve error handling
-rw-r--r-- | lib/getMeetingpointData.js | 11 |
1 files changed, 2 insertions, 9 deletions
diff --git a/lib/getMeetingpointData.js b/lib/getMeetingpointData.js index 9a51cfb..94cf36c 100644 --- a/lib/getMeetingpointData.js +++ b/lib/getMeetingpointData.js @@ -59,7 +59,7 @@ function getValidWeekNumbers(page) { function requestData() { lastUpdate = new Date() - return request(`http://www.meetingpointmco.nl/Roosters-AL/doc/dagroosters/frames/navbar.htm`).then((response) => { + return request(`http://www.meetingpointmco.nl/Roosters-AL/doc/dagroosters/frames/navbar.htm`, { timeout: 5000 }).then((response) => { const page = cheerio.load(response.body) const users = getUsers(page) const validWeekNumbers = getValidWeekNumbers(page) @@ -71,17 +71,10 @@ function requestData() { } function getMeetingpointData () { - if (lastUpdate == null) { + if (lastUpdate == null || new Date() - lastUpdate > 10 * 60 * 1000) { // 10 minutes return requestData() } else if (!meetingpointData) { - // The first request hasn't resolved yet, throw an error. return Promise.reject() - } else if (new Date() - lastUpdate > 10 * 60 * 1000) { // 10 minutes - return requestData().catch(function () { - console.warn('Unable to update userIndex, using cached.') - - return meetingpointData - }) } else { return Promise.resolve(meetingpointData) } |