apache / nano

Nano is now part of Apache CouchDB. Repo moved to https://GitHub.com/apache/couchdb-nano
https://github.com/apache/couchdb-nano
Other
1.13k stars 157 forks source link

Missing db.attachment.head method #295

Open hellboy81 opened 9 years ago

hellboy81 commented 9 years ago

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 commented 9 years ago

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)
}
carlosduclos commented 7 years ago

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