Coverage for sites/comments_site/comments_database/utils.py: 89%

7 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2024-02-28 09:09 +0000

1from rest_framework.response import Response 

2from rest_framework.status import HTTP_400_BAD_REQUEST 

3 

4from comments_api.constants import API_MESSAGE_KEY 

5 

6 

7def response_with_error_message( 

8 error_message: str, response_http_status: int = HTTP_400_BAD_REQUEST, base_data: dict = {} 

9) -> Response: 

10 """Returns a DRF (error) response with an added message.""" 

11 if error_message: 11 ↛ 13line 11 didn't jump to line 13, because the condition on line 11 was never false

12 base_data[API_MESSAGE_KEY] = error_message 

13 return Response(base_data, status=response_http_status)