nano
nano copied to clipboard
Missing db.attachment.head method
I should pipe attachment stream to response stream with correct error handling (missing attachment, etc..)
I am trying to check if attachment exists with db.attachment.head, but I am missing this method in nano
Ha
var attachment = db.attachment.get(documentName, attName, function (err) {
if (err) {
if (err.statusCode === 404) {
// Handle attachment not found
} else {
// Handle other error
}
}
}
// Still executing even if attachment not found
// Original CouchDB error response is has been sended to client BEFORE callback with error is called
attachment.pipe(res)
As I mentioned db.attachment.get can not work simultaneously with pipe and error handling:
var attachment = db.attachment.get(documentName, attName, function (err) {
if (err) {
if (err.statusCode === 404) {
// Handle attachment not found
} else {
// Handle other error
}
}
// Throws error:
// You cannot pipe after data has been emitted from the response.
attachment.pipe(res)
}
This repository has been merged into apache/couchdb-nano, please continue the discussion here.