nano icon indicating copy to clipboard operation
nano copied to clipboard

Missing db.attachment.head method

Open hellboy81 opened this issue 10 years ago • 2 comments

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)

hellboy81 avatar Nov 03 '15 07:11 hellboy81

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)
}

hellboy81 avatar Nov 03 '15 07:11 hellboy81

This repository has been merged into apache/couchdb-nano, please continue the discussion here.

carlosduclos avatar Mar 17 '17 13:03 carlosduclos