request endpoint finds type by body not query. Better error handling on what goes wrong if incorrect type or missing body parameter.
This commit is contained in:
@@ -88,7 +88,7 @@ class TMDB {
|
|||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
.then(() => this.cache.get(cacheKey))
|
.then(() => this.cache.get(cacheKey))
|
||||||
.catch(() => this.tmdb('movieInfo', query))
|
.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 => this.cache.set(cacheKey, response))
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -7,14 +7,19 @@ const tmdb = new TMDB(cache, configuration.get('tmdb', 'apiKey'));
|
|||||||
const request = new RequestRepository();
|
const request = new RequestRepository();
|
||||||
|
|
||||||
const typeFunction = (type) => {
|
const typeFunction = (type) => {
|
||||||
type = type.toLowerCase();
|
if (type !== undefined) {
|
||||||
if (type === 'movie') {
|
type = type.toLowerCase();
|
||||||
return tmdb.movieInfo;
|
|
||||||
} else if (type === 'show') {
|
if (type === 'movie') {
|
||||||
return tmdb.showInfo;
|
return tmdb.movieInfo;
|
||||||
} else {
|
} else if (type === 'show') {
|
||||||
throw new Error("Unprocessable Entity: Invalid type for query 'type'. Allowed values: movie|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
|
* Controller: Request by id with type param
|
||||||
@@ -24,10 +29,10 @@ const typeFunction = (type) => {
|
|||||||
*/
|
*/
|
||||||
function requestTmdbIdController(req, res) {
|
function requestTmdbIdController(req, res) {
|
||||||
const requestId = req.params.id;
|
const requestId = req.params.id;
|
||||||
const { type } = req.query;
|
const tmdbType = req.body.tmdbType;
|
||||||
|
|
||||||
Promise.resolve()
|
Promise.resolve()
|
||||||
.then(() => typeFunction(type))
|
.then(() => typeFunction(tmdbType))
|
||||||
// .then(() => checkType
|
// .then(() => checkType
|
||||||
.then(() => tmdb.movieInfo(requestId))
|
.then(() => tmdb.movieInfo(requestId))
|
||||||
.then((movie) => request.addTmdb(movie))
|
.then((movie) => request.addTmdb(movie))
|
||||||
|
|||||||
Reference in New Issue
Block a user