pouchdb - CouchDB: bulk_docs returning incorrect status code -


i'm working on syncing pouchdb database (with angular) couchdb database.

when replication in progress, code issuing post request bulk update http://127.0.0.1:5984/testdb/_bulk_docs.

i have validation rule on database reject unauthorized writes, , generates forbidden error. therefore, server responding json response [{"id":"0951db944e729c981ad3964c22002d55","rev":"8-ccdcb52743cae43c5870113f09f2e25a","error":"forbidden","reason":"not authorized"}]

according to docs (at end of page), above response should generate 417 expectation failed status code. however, generates 201 created status code.

because of incorrect response code, client (pouchdb) shows records synced, updates not written server (couchdb).

is there config option change status code?

fore reference, validate_doc_update function following.

function(newdoc, olddoc, userctx){      if (!userctx) throw({forbidden: 'need user update'});      if((userctx.roles.indexof('_admin') == -1) && (userctx.roles.indexof('backend:manager') == -1)){            throw({forbidden: "not authorized"});     } } 

the 417:expectation failed status code works when all_or_nothing parameter set true. default parameter false.

the default bulk update transaction mode in couchdb non atomic guarantees of documents saved. if document not saved api returns error object got along list of documents in fact saved. 201 seems correct response.

then you've got walk through response find documents failed , manually update them.

in case of all_or_nothing mode success returned if documents have been updated.

while syncing can use _replicate endpoint has many other features bulk update not have.


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -