generated from RealDevSquad/website-template
-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Description
Issue Description
The "create task" endpoint handles exceptions locally within the view and service layers, which is inconsistent with the rest of the application, where exceptions are managed by a global exception handler (exception_handler.py). This refactoring task aims to align the create task endpoint's error handling with the project's standard pattern.
PRD: https://docs.google.com/document/d/1KOFK8ISE1hy9h8QjNbrObo6QKeM1I-rYZTJ8ygwfxhg/edit?usp=sharing
Expected Behavior
- When a POST request to
/tasksresults in an error (e.g., validation error, repository error), the exception should be propagated up to the global exception handler. - The global exception handler (
todo/exceptions/exception_handler.py) should be responsible for formatting and returning the final error response to the client. - The local
try...exceptblocks inTaskListView.postandTaskService.create_taskthat generate ApiErrorResponse objects should be removed. - The service layer should raise specific, custom exceptions (e.g.,
DRFValidationErrorfor validation issues) or let repository/database exceptions propagate, which the global handler will then catch.
Current Behavior
- The
TaskListView.postmethod intodo/views/task.pycontains atry...exceptblock that catchesValueErrorand manually constructs anApiErrorResponse. - The
TaskService.create_taskmethod intodo/services/task_service.pyalso hastry...exceptblocks. It catches exceptions, wraps them in anApiErrorResponse, and re-raises them as a genericValueError. - This local handling prevents the global exception handler from processing errors for this endpoint, leading to inconsistent error response formats and duplicated logic. For example, validation errors for missing labels are wrapped in a
ValueErrorwith anApiErrorResponseinstead of raising aDRFValidationErrorthat the global handler can process correctly.
Screenshots
N/A
Reproducibility
- This issue is reproducible
- This issue is not reproducible
Steps to Reproduce
- Send a `POST` request to the `/tasks` endpoint with a non-existent `label` ID in the payload.
- Set a breakpoint in `todo/views/task.py` inside the `except ValueError` block of the `post` method.
- Observe that the exception is caught and handled locally, instead of being processed by the global exception handler in `todo/exceptions/exception_handler.py`.
- Compare this behaviour with error handling in other endpoints, like `TaskDetailView`, which relies on the global handler.
Severity/Priority
- Critical
- High
- Medium
- Low
Additional Information
This issue primarily involves refactoring the following methods:
todo.views.task.TaskListView.posttodo.services.task_service.TaskService.create_task
The goal is to make their exception handling similar to TaskDetailView and other parts of the service layer.
Checklist
- I have read and followed the project's code of conduct.
- I have searched for similar issues before creating this one.
- I have provided all the necessary information to understand and reproduce the issue.
- I am willing to contribute to the resolution of this issue.
Metadata
Metadata
Assignees
Labels
No labels