request.get(url + path, function (err, response, body) {
if (err) return callback(err)
- callback(null, JSON.parse(body))
+ try {
+ const json = JSON.parse(body)
+ return callback(null, json)
+ } catch (err) {
+ return callback(err)
+ }
})
}
return res.sendStatus(500)
}
- req.body.data = JSON.parse(decrypted)
- delete req.body.key
+ try {
+ req.body.data = JSON.parse(decrypted)
+ delete req.body.key
+ } catch (err) {
+ logger.error('Error in JSON.parse', { error: err })
+ return res.sendStatus(500)
+ }
next()
})