I'm working on syncing a PouchDB database (with Angular) with a CouchDB database.
When the replication is in progress, the code is issuing a POST request to do a bulk update to http://127.0.0.1:5984/testdb/_bulk_docs
.
I have a validation rule on database to reject unauthorized writes, and it generates a forbidden error. Therefore, the server is responding with a JSON response as [{"id":"0951db944e729c981ad3964c22002d55","rev":"8-ccdcb52743cae43c5870113f09f2e25a","error":"forbidden","reason":"Not Authorized"}]
According to the docs (at the end of the page), the above response should generate a 417 Expectation Failed
status code. However, it currently generates a 201 Created
status code.
Because of the incorrect response code, the client (PouchDB) shows as all records synced, but the updates are not written to the server (CouchDB).
Is there a config option to change this status code?
Fore reference, my validate_doc_update
function is as following.
function(newDoc, oldDoc, userCtx){
if (!userCtx) throw({forbidden: 'Need a user to update'});
if((userCtx.roles.indexOf('_admin') == -1) && (userCtx.roles.indexOf('backend:manager') == -1)){
throw({forbidden: "Not Authorized"});
}
}