Error handling for themoviedb api response codes that are not 200. Started with 401 and 404. See issue #116 for info.

This commit is contained in:
2019-07-26 21:52:20 +02:00
parent afb7af46b8
commit 3b27af1f83
3 changed files with 27 additions and 10 deletions

View File

@@ -22,30 +22,31 @@ const tmdbShowInfo = (id) => {
*/
function requestTmdbIdController(req, res) {
const { id, type } = req.body
console.log('body', req.body)
console.log('id & type', id, type)
const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
const user_agent = req.headers['user-agent'];
const user = req.loggedInUser;
let mediaFunction = undefined
if (id === undefined || type === undefined) {
res.status(422).send({ success: false, message: "'Missing parameteres: 'id' and/or 'type'"})
}
if (type === 'movie') {
console.log('movie')
mediaFunction = tmdbMovieInfo
} else if (type === 'show') {
console.log('show')
mediaFunction = tmdbShowInfo
} else {
res.status(422).send({ success: false, error: 'Incorrect type. Allowed types: "movie" or "show"'})
}
mediaFunction(id)
.catch((error) => { console.error(error); res.status(404).send({ success: false, error: 'Id not found' }) })
// .catch((error) => { console.error(error); res.status(404).send({ success: false, error: 'Id not found' }) })
.then((tmdbMedia) => request.requestFromTmdb(tmdbMedia, ip, user_agent, user))
.then(() => res.send({success: true, message: 'Request has been submitted.'}))
.catch((error) => {
res.status(501).send({ success: false, error: error.message });
res.send({ success: false, error: error.message });
})
}