Skip to content

Proper way to access response code in onResponse hook? #88

Closed
@jayden-chan

Description

@jayden-chan

I want to use the onResponse hook to print a log message every time a response is generated. Right now I am reading the value of set.status to determine the HTTP status code of the response. However in cases where Elysia responds early due to an error, the value of set.status is incorrect. For example if body validation fails, the server responds to the client with code 400 but the value of set.status is 500.

Is this the wrong way of determining info about the response? I did not see any other way in the docs or function signature. From what I can tell, the response itself isn't actually accessible in the onResponse hook.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions