mirror of
				https://github.com/Chocobozzz/PeerTube.git
				synced 2025-02-25 18:55:32 -06:00 
			
		
		
		
	Server: catch JSON.parse exceptions
This commit is contained in:
		@@ -198,7 +198,12 @@ function getForeignPodsList (url, callback) {
 | 
			
		||||
  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)
 | 
			
		||||
    }
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -34,8 +34,13 @@ function decryptBody (req, res, next) {
 | 
			
		||||
          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()
 | 
			
		||||
      })
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user