Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove 204 return falsey & add default expressjs behavior on emp… #412

Merged
merged 2 commits into from
Nov 30, 2024

Conversation

rsaz
Copy link
Contributor

@rsaz rsaz commented Nov 28, 2024

…ty-void return

Description

Described here: #255 (comment)
Test modified to validate timeout rather than 204

Related Issue

Motivation and Context

Not able to return error, middleware, next. Issue on ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client

How Has This Been Tested?

it("should work for controller methods who's return value is falsey", (done) => {
            @controller("/user")
            class TestController {
                @httpDelete("/") public async delete(): Promise<void> {
                    //
                }
            }

            server = new InversifyExpressServer(container);
            void supertest(server.build())
                .delete("/user")
                .timeout({ response: 1000, deadline: 2000 })
                .end((err, res) => {
                    if (err) {
                        if (err.timeout) {
                            // The request timed out as expected because no response was sent
                            done();
                        } else {
                            // Some other error occurred
                            done(err);
                        }
                    } else {
                        // If we get here, the request did not hang, and a response was received
                        done(new Error("Expected request to hang, but a response was received"));
                    }
                });
        });

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Copy link
Member

@notaphplover notaphplover left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

Can you update the changelog with a new entry in the unreleased section?

@rsaz
Copy link
Contributor Author

rsaz commented Nov 29, 2024

Looks great!

Can you update the changelog with a new entry in the unreleased section?

Done!

@notaphplover notaphplover merged commit f17992c into master Nov 30, 2024
4 checks passed
@notaphplover notaphplover deleted the bug/255-cant-set-headers-after-they-are-sent branch November 30, 2024 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants