Merge pull request 'improve-search-error-handling' (#8) from improve-search-error-handling into main

Reviewed-on: #8
This commit is contained in:
Edward Tirado Jr 2025-06-30 20:38:39 +00:00
commit 8602784c0d

View file

@ -9,4 +9,17 @@ def omdb_search(request):
search_type = request.GET.get("type")
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)