Verify that respond has content, if so send the content back. If no content was found, send 404 status and error message
This commit is contained in:
@@ -7,7 +7,14 @@ function searchRequestController(req, res) {
|
||||
|
||||
requestRepository.searchRequest(query, page, type)
|
||||
.then((movies) => {
|
||||
res.send(movies);
|
||||
// Verify that respond has content, if so send the content back
|
||||
if (movies.length > 0 && movies != null) {
|
||||
res.send(movies);
|
||||
}
|
||||
// If no content was found, send 404 status and error message
|
||||
else {
|
||||
res.status(404).send({success: false, error: 'Search query did not return any results.'})
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
res.status(500).send({success: false, error: error.message });
|
||||
|
||||
Reference in New Issue
Block a user