fix(Public): handle URL erros

This commit is contained in:
Matthieu Bessat 2020-08-04 23:49:50 +02:00
parent 09269a95b7
commit 8231d58c82

View file

@ -70,11 +70,11 @@ export default class PublicController {
organizationsJSON: JSON.stringify(organizationsData)
})
}).catch(err => () => {
console.log(err)
console.error(err)
return ErrorController.handleServerError(err, req, res, [])
})
}).catch(err => () => {
console.log(err)
console.error(err)
return ErrorController.handleServerError(err, req, res, [])
})
}
@ -138,13 +138,28 @@ export default class PublicController {
}
if (Utils.isStrUsable(version.contacts, 'facebook')) {
try {
version.contacts.facebookLabel = new URL(version.contacts.facebook).pathname.replace('/', '')
} catch (err) {
console.error(err)
version.contacts.facebook = version.contacts.facebookLabel = "OULA, c'est pas bon :("
}
}
if (Utils.isStrUsable(version.contacts, 'twitter')) {
try {
version.contacts.twitterLabel = new URL(version.contacts.twitter).pathname.replace('/', '')
} catch (err) {
console.error(err)
version.contacts.twitter = version.contacts.twitterLabel = "OULA, c'est pas bon :("
}
}
if (Utils.isStrUsable(version.contacts, 'instagram')) {
try {
version.contacts.instagramLabel = new URL(version.contacts.instagram).pathname.replace('/', '')
} catch (err) {
console.error(err)
version.contacts.instagram = version.contacts.instagramLabel = "OULA, c'est pas bon :("
}
}
}
if (Array.isArray(version.gallery)) {
@ -153,10 +168,8 @@ export default class PublicController {
return media
})
}
version.cutDescription = Utils.isStrUsable(version, 'descriptionLong') && version.descriptionLong.length > 200
if (Utils.isUsable(version, 'schedule')) {
// TODO: Rassembler les horaires qui sont dans le même jour, uniquement pour le front
version.schedule = version.schedule.map((s: any) => {
let days = [...new Set(s.when.map((w: any) => w.day))]
return {
@ -173,25 +186,28 @@ export default class PublicController {
description: s.description
}
})
}
version.cutDescription = Utils.isStrUsable(version, 'descriptionLong') && version.descriptionLong.length > 200
// if (version.cutDescription) {
// version.descriptionFirstHalf = version.descriptionLong.substr(0, 200) // not gonna lie
// version.descriptionSecondHalf = version.descriptionLong.substr(200)
// }
let hour = lastPublished.toLocaleTimeString('fr-FR', { timezone: '+2' })
if (hour.charAt(1) === ':') {
hour = '0' + hour
}
// let hour = lastPublished.toLocaleTimeString('fr-FR', { timezone: '+2' })
// if (hour.charAt(1) === ':') {
// hour = '0' + hour
// }
res.render('organization.twig', {
layout: 'standalone',
data: version,
lastPublished: lastPublished.toLocaleDateString('fr-FR') + ' ' + hour.substr(0, 5),
//lastPublished: lastPublished.toLocaleDateString('fr-FR') + ' ' + hour.substr(0, 5),
isProposed,
id: org.get('_id')
})
}
}).catch(err => () => {
console.log(err)
console.error(err)
return ErrorController.handleServerError(err, req, res, [])
})
}