diff --git a/seasoned_api/src/tmdb/tmdb.js b/seasoned_api/src/tmdb/tmdb.js index bfe895c..74f68c8 100644 --- a/seasoned_api/src/tmdb/tmdb.js +++ b/seasoned_api/src/tmdb/tmdb.js @@ -88,7 +88,7 @@ class TMDB { return Promise.resolve() .then(() => this.cache.get(cacheKey)) .catch(() => this.tmdb('movieInfo', query)) - .catch(() => { throw new Error('Could not find a movie with that id.'); }) + .catch((error) => { console.log(error); throw new Error('Could not find a movie with that id.'); }) .then(response => this.cache.set(cacheKey, response)) .then((response) => { try { diff --git a/seasoned_api/src/webserver/controllers/request/requestTmdbId.js b/seasoned_api/src/webserver/controllers/request/requestTmdbId.js index ef4e913..46ad956 100644 --- a/seasoned_api/src/webserver/controllers/request/requestTmdbId.js +++ b/seasoned_api/src/webserver/controllers/request/requestTmdbId.js @@ -7,14 +7,19 @@ const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey')); const request = new RequestRepository(); const typeFunction = (type) => { - type = type.toLowerCase(); - if (type === 'movie') { - return tmdb.movieInfo; - } else if (type === 'show') { - return tmdb.showInfo; - } else { - throw new Error("Unprocessable Entity: Invalid type for query 'type'. Allowed values: movie|show"); + if (type !== undefined) { + type = type.toLowerCase(); + + if (type === 'movie') { + return tmdb.movieInfo; + } else if (type === 'show') { + return tmdb.showInfo; + } else { + throw new Error("Unprocessable Entity: Invalid type for body parameter 'type'. Allowed values: movie|show"); + } } + throw new Error("tmdbType body parameter not defined. Allowed values: movie|show") + } /** * Controller: Request by id with type param @@ -24,10 +29,10 @@ const typeFunction = (type) => { */ function requestTmdbIdController(req, res) { const requestId = req.params.id; - const { type } = req.query; + const tmdbType = req.body.tmdbType; Promise.resolve() - .then(() => typeFunction(type)) + .then(() => typeFunction(tmdbType)) // .then(() => checkType .then(() => tmdb.movieInfo(requestId)) .then((movie) => request.addTmdb(movie))