Skip to content

Instantly share code, notes, and snippets.

@jpallen
Created October 10, 2012 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jpallen/3865644 to your computer and use it in GitHub Desktop.
Save jpallen/3865644 to your computer and use it in GitHub Desktop.
errorhandling
function respondWithError(response, namespace, message, status) {
if (!status) {
status = 500;
}
console.log(namespace, message);
response.setHeader('Content-Type','application/json');
response.writeHead(status);
response.end(JSON.stringify("Missing guid"));
}
function handleDelete(request, response) {
if ( ! "guid" in request.url.query)) {
respondWithError(response, 'Blogs', 'Error - Missing guid in handleDelete', 400);
return;
}
getBlogByGuid(request.url.query.guid, function gotBlog(err, blog) {
if(err) {
respondWithError(response, 'Blogs', 'Error in getBlogByGuid callback in handleDelete');
return;
}
deleteDocumentById(blog.id, function deletedBlog(err, status) {
if(err) {
respondWithError(response, 'Blogs', 'Error in deleteDocumentById callback in handleDelete');
return;
}
// Deleted OK
response.writeHead(200);
response.end('Blog Deleted');
})
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment