added better error handling to movie search
This commit is contained in:
parent
b25f5c66e1
commit
9dce0f1ec4
1 changed files with 15 additions and 1 deletions
|
@ -3,10 +3,24 @@ from movie_db.db_providers.omdb import OMDb
|
||||||
|
|
||||||
|
|
||||||
def omdb_search(request):
|
def omdb_search(request):
|
||||||
|
print("ENTERING MOVIE SEARCH")
|
||||||
query = request.GET.get("q")
|
query = request.GET.get("q")
|
||||||
if not query:
|
if not query:
|
||||||
return JsonResponse({"Error": "Missing query"}, status=400)
|
return JsonResponse({"Error": "Missing query"}, status=400)
|
||||||
|
|
||||||
search_type = request.GET.get("type")
|
search_type = request.GET.get("type")
|
||||||
omdb = OMDb()
|
omdb = OMDb()
|
||||||
return JsonResponse(omdb.search(query, {"type": search_type}), safe=False)
|
|
||||||
|
results = omdb.search(query, {"type": search_type})
|
||||||
|
if "error" in results:
|
||||||
|
return parse_error(results)
|
||||||
|
|
||||||
|
return JsonResponse(results, safe=False)
|
||||||
|
|
||||||
|
|
||||||
|
def parse_error(results):
|
||||||
|
error_json = results["error"]
|
||||||
|
if "Error" in error_json and error_json["Error"] == "Movie not found!":
|
||||||
|
return JsonResponse({}, status=404)
|
||||||
|
else:
|
||||||
|
return JsonResponse("Error while searching for movie.", status=500)
|
Loading…
Add table
Reference in a new issue