Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions starlette_jsonapi/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ async def handle_request(
try:
if request.method not in cls.allowed_methods:
raise JSONAPIException(status_code=405)
resource = cls(request, request_context, *args, **kwargs)
handler = getattr(resource, handler_name, None)
response = await handler(*args, **kwargs)
response = await cls.execute_handler(request, request_context, handler_name, *args, **kwargs)
except Exception as e:
response = await cls.handle_error(request, request_context, exc=e)

Expand All @@ -149,6 +147,23 @@ async def handle_request(

return response

@classmethod
async def execute_handler(
cls, request: Request, request_context: dict, handler_name: str,
*args, **kwargs
) -> Response:
"""
Finds a handler on this resource given its name and calls it.

:param request: current HTTP request
:param request_context: current request context
:param handler_name: name of the handler callable
"""
resource = cls(request, request_context, *args, **kwargs)
handler = getattr(resource, handler_name, None)
response = await handler(*args, **kwargs)
return response

def process_sparse_fields_request(self, serialized_data: dict, many: bool = False) -> dict:
"""
Processes sparse fields requests by calling
Expand Down