Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

fix(logging): reading empty body when extracting request data #207

Merged
merged 4 commits into from
Jan 7, 2023

Conversation

gazorby
Copy link
Collaborator

@gazorby gazorby commented Jan 7, 2023

Fixes "Error in logging before-send handler!" error that occurs when extracting request data with an empty body.

Closes #208

This fixes simple cases like the following:

from starlite import Controller, NotAuthorizedException, Starlite, post
from starlite_saqlalchemy import ConfigureApp, PluginConfig


class MyController(Controller):
    path: str = "/api"

    @post(path="/")
    async def handle_post(self) -> str:
        raise NotAuthorizedException()

starlite_saqlalchemy_config = PluginConfig(do_worker=False, do_sentry=False)

app = Starlite(
    route_handlers=[MyController],
    on_app_init=[ConfigureApp(config=starlite_saqlalchemy_config)],
)

Where logging currently shows:

2023-01-07T20:56:37.464647Z [error    ] Error in logging before-send handler!
NoneType: None

Instead of something like:

2023-01-07T21:07:29.957873Z [info     ] HTTP                           request={'path': '/api', 'method': 'POST', 'content_type': ('application/x-www-form-urlencoded', {}), 'headers': {'host': 'localhost:7755', 'user-agent': 'curl/7.87.0', 'accept': '*/*', 'content-length': '15', 'content-type': 'application/x-www-form-urlencoded'}, 'cookies': {}, 'query': b'', 'path_params': {}, 'body': None} response={'status_code': 401, 'cookies': {}, 'headers': {'content-type': 'application/json', 'content-length': '43'}, 'body': b'{"status_code":401,"detail":"Unauthorized"}'}

@peterschutt peterschutt merged commit 5400e44 into topsport-com-au:main Jan 7, 2023
@peterschutt
Copy link
Member

thanks @gazorby!

@peterschutt
Copy link
Member

What is the .tool-versions file for? You happy if I .gitignore that?

@gazorby
Copy link
Collaborator Author

gazorby commented Jan 7, 2023

Oh sorry didn't want to push that!
It's a configuration file for asdf-vm because I'm still using python 3.10 on my system. It allows me to use 3.11 when working on this project ;)

@peterschutt
Copy link
Member

OK, cool. I use pyenv for similar but the mulit-tool aspect of that sounds interesting!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(logging): logging error when using rich
2 participants