Skip to content

Commit

Permalink
refactor(api): move jsonResponse logic to APIInvalidInputException
Browse files Browse the repository at this point in the history
  • Loading branch information
nsantacruz committed Nov 28, 2024
1 parent 220fb2b commit 66c0cf3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion api/api_errors.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
"""
Classes for API errors
"""
from sefaria.client.util import jsonResponse


class APIInvalidInputException(Exception):
"""
When data in an invalid format is passed to an API
"""
pass
def __init__(self, message):
super().__init__(message)
self.message = message

def to_json_response(self):
return jsonResponse({"invalid_input_error": self.message}, status=400)
2 changes: 1 addition & 1 deletion sefaria/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def find_refs_api(request):
try:
return jsonResponse(make_find_refs_response(request))
except APIInvalidInputException as e:
return jsonResponse({"error": str(e)}, status=400)
return e.to_json_response()


@api_view(["GET"])
Expand Down

0 comments on commit 66c0cf3

Please sign in to comment.