Created
October 10, 2012 13:26
-
-
Save jpallen/3865644 to your computer and use it in GitHub Desktop.
errorhandling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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