Skip to content

Conversation

@MEHRSHAD-MIRSHEKARY
Copy link
Collaborator

No description provided.

…nt error responses

- Introduces the `ExceptionHandler` class to handle exceptions and return consistent JSON error responses across the application.
- Maps specific Django exceptions (e.g., `ObjectDoesNotExist`, `ValidationError`, `DatabaseError`) to appropriate HTTP status codes and messages.
- Provides detailed error information in debug mode, including exception type, message, and traceback.
- Supports handling of common Django exceptions (e.g., `PermissionDenied`, `BadRequest`, `IntegrityError`) and falls back to a generic 500 Internal Server Er
ror for unhandled exceptions.

Closes Lazarus-org#29
- Added async-aware logic to handle both synchronous and asynchronous requests seamlessly using Django's `sync_to_async` utility.
- Updated the `BaseMiddleware` class to support async mode by checking if the `get_response` function is a coroutine and marking the middleware as async-capa
ble.
- Ensured compatibility with Django's ASGI stack by properly handling async responses and exceptions.
- Maintained existing synchronous functionality while extending support for async workflows, ensuring backward compatibility.
- Added async-specific logic to process JSON responses consistently for both success and error cases.
- Improved exception handling to work seamlessly in both sync and async contexts, leveraging the `ExceptionHandler` class for consistent error responses.

Closes Lazarus-org#28
@MEHRSHAD-MIRSHEKARY MEHRSHAD-MIRSHEKARY self-assigned this Feb 9, 2025
@MEHRSHAD-MIRSHEKARY MEHRSHAD-MIRSHEKARY added the enhancement New feature or request label Feb 9, 2025
Copy link
Collaborator Author

@MEHRSHAD-MIRSHEKARY MEHRSHAD-MIRSHEKARY left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed two issues related to middleware,
I will update the dependencies & configuration files in the next PR.

@ARYAN-NIKNEZHAD ARYAN-NIKNEZHAD merged commit 98f1263 into Lazarus-org:main Feb 9, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants