Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialBen McMahan
7,922 PointsBug? "Cannot set headers after they are sent to the client"
Noticed in my editor that the terminal was throwing the following error:
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
This is because Andrew sets a redirect but does not return it, meaning that all of the code beyond the redirect runs anyway.
if (!side) {
res.redirect(`/cards/${id}?side=question`);
}
should be
if (!side) {
// RETURN the redirect, exiting out of the function
return res.redirect(`/cards/${id}?side=question`);
}
2 Answers
Steven Parker
231,275 PointsPosting here will get the info to other students, but it may not be seen by the staff. You may also want to report a bug as described on the Support page.
It might even get you a "special Exterminator badge".
Jonathan Drake
Full Stack JavaScript Techdegree Student 11,668 PointsThat fixed the same issue I was having. Functionality was obviously still present, but the error message in the terminal was irritating. Thanks.
Ben McMahan
7,922 PointsBen McMahan
7,922 PointsSteven,
Apparently, this was addressed in a subsequent video. Why this wasn't covered in this one is a mystery.
And yes, I'm aware (thanks to your similar replies elsewhere) of maybe earning a badge.
I am hoping that staff reads the forum and this post can help others if they are trying to debug code in this lesson.