Skip to content

Commit 795ac7b

Browse files
committed
Fix error when response has no content-type
When the response didn't contain a content-type header (e.g. an empty HTTP 204 response), APILoggerMiddleware threw a KeyError exception.
1 parent 5a7e195 commit 795ac7b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drf_api_logger/middleware/api_logger_middleware.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def __call__(self, request):
8181

8282
headers = get_headers(request=request)
8383
method = request.method
84-
if response['content-type'] == 'application/json':
84+
if 'content-type' in response and response['content-type'] == 'application/json':
8585
if getattr(response, 'streaming', False):
8686
response_body = '** Streaming **'
8787
else:

0 commit comments

Comments
 (0)