examples/attachment-stream2.js
function initDocument (docName) {
  return db.getDocument(dbName, docName)
    .then(response => response.data._rev) // document already exists
    .catch(response => {
      if (response.status === 404) {
        // create new document
        return db.createDocument(dbName, {foo: 'bar'}, docName)
          .then(response => response.data.rev)
      } else {
        // real error
        return Promise.reject(response)
      }
    })
}
function initDocument (docName) {
  return db.getDocument(dbName, docName)
    .then(response => response.data._rev) // document already exists
    .catch(response => {
      if (response.status === 404) {
        // create new document
        return db.createDocument(dbName, {foo: 'bar'}, docName)
          .then(response => response.data.rev)
      } else {
        // real error
        return Promise.reject(response)
      }
    })
}
function initDocument ( docName ) { return db . getDocument ( dbName , docName ) . then ( response => response . data . _rev ) // document already exists . catch ( response => { if ( response . status === 404 ) { // create new document return db . createDocument ( dbName , { foo : 'bar' } , docName ) . then ( response => response . data . rev ) } else { // real error return Promise . reject ( response ) } } ) }
get existing document or create new
@param  {String} docName
@return {Promise} - fulfilled with document revision
get existing document or create new