improve-search-error-handling #8
1 changed files with 14 additions and 1 deletions
|
@ -9,4 +9,17 @@ def omdb_search(request):
|
||||||
|
|
||||||
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