routing-controllers icon indicating copy to clipboard operation
routing-controllers copied to clipboard

fix: socket hang up when CurrentUser lookup fails

Open dickfickling opened this issue 3 years ago • 2 comments

Description

I think this is related to https://github.com/typestack/routing-controllers/issues/243. If currentUserChecker doesn't return a user, we try to send headers after the socket is destroyed, which causes issues. Adding the middleware here fixes the problem but breaks routing-controller's logging.

Check here for example code. Running jest in that repo will output:

  User Controller Tests
    GET /users
      ✕ should throw an error if the user cannot be found (44 ms)

  ● User Controller Tests › GET /users › should throw an error if the user cannot be found

    socket hang up



Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        2.46 s, estimated 3 s

Expected behavior

currentUserChecker should be able to return null / false

Actual behavior

if currentUserChecker returns false, headers are sent after the socket is terminated, and express gets unhappy

dickfickling avatar Jan 07 '21 07:01 dickfickling

I'm also getting this when class-validation fails

iamchathu avatar Jul 23 '22 19:07 iamchathu

This issue doesn't appear when default error handler is false

iamchathu avatar Jul 24 '22 07:07 iamchathu