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:
@@ -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 });
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user