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

Controllers should not be forced to send a response for falsey return values #126

Merged
merged 1 commit into from
Jan 24, 2018
Merged

Controllers should not be forced to send a response for falsey return values #126

merged 1 commit into from
Jan 24, 2018

Conversation

rmblstrp
Copy link
Contributor

@rmblstrp rmblstrp commented Jan 23, 2018

Description

Modified the handling of the the controller's return value so that a the status code 204 is set if the value is undefined after which it will send the result regardless of the type of value.

Related Issue

inversify/InversifyJS#764

Motivation and Context

Controllers should not be forced to send a response if the value they are returning is undefined, NULL, false, or otherwise evaluates as false. Without this change all responses would need to be wrapped to ensure that response.send() is called.

How Has This Been Tested?

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

    server = new InversifyExpressServer(container);
    supertest(server.build())
        .delete("/user")
        .expect(204, "", done);
});

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.

Express requests will hang when controller methods do not return a
response or when return a NULL value is returned.

inversify/InversifyJS#764
@remojansen remojansen merged commit 32377a5 into inversify:master Jan 24, 2018
@remojansen
Copy link
Member

👍 thanks a lot for the PR

@rmblstrp
Copy link
Contributor Author

rmblstrp commented Jan 24, 2018 via email

@remojansen
Copy link
Member

Hi @rmblstrp I just released [email protected] and it contains your fix 🎉

@rmblstrp
Copy link
Contributor Author

rmblstrp commented Jan 25, 2018 via email

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

Successfully merging this pull request may close these issues.

2 participants