aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2018-02-16 23:12:52 +0100
committerNoah Loomans <noahloomans@gmail.com>2018-02-16 23:12:52 +0100
commitf1a408a515505ab1833f2f1c8fe647ee7f2102ee (patch)
tree44ace1292032b37d3e54e7d98e324f75ec7d26e8 /src
parente395da54cc308ff78ce2e64dc4e0ec0b9338c1aa (diff)
Return data without alts if alts fail
Diffstat (limited to 'src')
-rw-r--r--src/server/lib/getMeetingpointData.js27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/server/lib/getMeetingpointData.js b/src/server/lib/getMeetingpointData.js
index 12bcd28..2e8a6ea 100644
--- a/src/server/lib/getMeetingpointData.js
+++ b/src/server/lib/getMeetingpointData.js
@@ -63,10 +63,10 @@ function combineUsers(usersArrays) {
function getAlts(users) {
const requests = users.map(user =>
- request(getUrlOfUser('dag', user.type, user.index, 7), { encoding: null }));
+ request(getUrlOfUser('dag', user.type, user.index, 7), { timeout: 8000, encoding: null }));
- return Promise.all(requests).then((teacherResponses) => {
- return teacherResponses.map((teacherResponse, index) => {
+ return Promise.all(requests).then(teacherResponses =>
+ teacherResponses.map((teacherResponse, index) => {
const utf8Body = iconv.decode(teacherResponse.body, 'iso-8859-1');
const teacherResponseBody = cheerio.load(utf8Body);
@@ -76,8 +76,7 @@ function getAlts(users) {
...users[index],
alt: teacherName,
};
- });
- });
+ }));
}
function getMeetingpointData() {
@@ -97,11 +96,19 @@ function getMeetingpointData() {
const teachers = users.filter(user => user.type === 't');
- return getAlts(teachers).then(teachersWithAlts => ({
- users: combineUsers([teachersWithAlts, users]),
- dailyScheduleWeeks,
- basisScheduleWeeks,
- }));
+ return getAlts(teachers)
+ .then(teachersWithAlts => ({
+ users: combineUsers([teachersWithAlts, users]),
+ dailyScheduleWeeks,
+ basisScheduleWeeks,
+ }))
+ .catch(() => ({
+ // Just return the user data without the alts if getAlts fails, since
+ // the alts are non-essential.
+ users,
+ dailyScheduleWeeks,
+ basisScheduleWeeks,
+ }));
});
}