Skip to content

Commit

Permalink
Adjust decompressor middleware logging
Browse files Browse the repository at this point in the history
  • Loading branch information
8R0WNI3 committed May 13, 2024
1 parent 383a19d commit f87b655
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions middleware/decompressor.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import json
import logging
import zlib

import falcon

import http_requests


logger = logging.getLogger(__name__)


class DecompressorMiddleware:
'''
Used to decompress request body in case it is compressed. The decompressed payload is stored
Expand All @@ -26,8 +22,6 @@ def process_resource(self, req: falcon.Request, resp: falcon.Response, resource,
decompressor = zlib.decompressobj(wbits=31)
data = decompressor.decompress(req.stream.read())
except Exception as e:
import traceback
logger.error(traceback.format_exc())
raise falcon.HTTPBadRequest(
title='Invalid gzip data',
description=e,
Expand All @@ -37,6 +31,12 @@ def process_resource(self, req: falcon.Request, resp: falcon.Response, resource,
raise NotImplementedError(content_encoding)

if req.content_type == 'application/json':
data = json.loads(data)
try:
data = json.loads(data)
except Exception as e:
raise falcon.HTTPBadRequest(
title=f'Invalid json data: {data}',
description=e,
)

req.context.media = data

0 comments on commit f87b655

Please sign in to comment.