question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

fix: [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client

See original GitHub issue

Hi all. When I have the following case, routing controllers fails and try to execute both functions:

@JsonController()
export class UserController {

    @Get("/users/me")
    getMe() {
      const id = 1;
       return userRepository.findById(id);
    }

    @Get("/users/:id")
    getOne(@Param("id") id: number) {
       return userRepository.findById(id);
    }
}

As far as I read it should execute first occurency not both. Thanks!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
doghappycommented, Nov 20, 2019

I have the same error. I use routing-controller in an existing express program. when I remove a middleware, it won’t throw again.

// catch 404 and forward to error handler
// app.use(function (req: Request, res: Response, next: NextFunction) {
//    res.status(404);
//    res.send({
//        code: 404,
//        message: "Not Found"
//    });
//});
2reactions
gruckioncommented, Jul 26, 2019

id is a number so you can use regex to be stricter on the matching.

@Get("/users/:id([0-9]+)")
Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Can't set headers after they are sent to the client
The error "Error: Can't set headers after they are sent." means that you're already in the Body or Finished state, but some function...
Read more >
Cannot set headers after they are sent to the client in JS
The "Cannot set headers after they are sent to the client" error occurs when the server in an express.js application sends more than...
Read more >
Resolving HTTP Cannot set headers after they are sent ... - Fjolt
Node.JS will occassionally throw an error called ERR_HTTP_HEADERS_SENT, which can be tricky to resolve. Let's take a look at how to fix it....
Read more >
Error [err_http_headers_sent]: cannot set headers after they ...
The error "Error: Can't set headers after they are sent." means that you're already in the Body or Finished state, but some function...
Read more >
cannot set headers after they are sent to the client - You.com
This error occurs when you sent a response before and then you try to send response again. For this you have to check...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found