Skip to content

@jpallen /errorhandling.js forked from twistdigital/errorhandling.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.