public
Created — forked from twistdigital/errorhandling.js

errorhandling

  • Download Gist
errorhandling.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
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');
})
});
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.