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

Always send a response #47

Open
oliverjam opened this issue May 7, 2021 · 0 comments
Open

Always send a response #47

oliverjam opened this issue May 7, 2021 · 0 comments

Comments

@oliverjam
Copy link

function get(request, response) {
const catId = request.params.catid;
console.log("catId", catId);
const cat = model.getCat(catId).then((cat) => {
response.send(cat.picture);
}).catch((error) => {
console.error(error);
})

Remember your route handlers always need to send a response, especially when errors occur. Here if you don't find a matching cat you just log the error and then stop. This causes the server to eventually time out if the user visits a nonexistent cat page (like /cats/999).

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

No branches or pull requests

2 participants