[ 
https://issues.apache.org/jira/browse/COUCHDB-2910?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15038567#comment-15038567
 ] 

Kerem Güneş commented on COUCHDB-2910:
--------------------------------------

Hi Alex, 

Right, I agree with you and I must be missed something on guide and this way 
seems correct.

But if we change our perspective like that, could you check this out please;

There is an TASK to completed well but NOT completed successfully.

START TASK
  -> update doc[0] = ok
  -> update doc[1] = ok
  -> update doc[2] = fail
ON ERROR
  -> rol back
  -> send "HTTP/1.0 409 Conflict"
END

As you can see here, I am (not only me but any developer that develop relying 
general rest concepts) expecting HTTP error code in a usual way to handle 
program error correctly.

This checks the server error relying on status code;
https://github.com/qeremy/couch-go/blob/master/src/couch/client/client.go#L110
This check any error from client.go;
https://github.com/qeremy/couch-go/blob/master/src/couch/database/database.go#L199
This informs the user about error if exists but fails to catch error basically 
cos of 201 code;
https://github.com/qeremy/couch-go/blob/master/src/couch/database/database.go#L199

Am I wrong at this point?

For an example  (even I know SQL != NoSQL);
https://github.com/qeremy/oppa/#batch-actions-aka-transactions

$batch = $agent->getBatch();
// set autocommit=0
$batch->lock();
try {
    $batch->queue('insert into `users` values(null,?,?)', ['John', 25]);
    $batch->queue('insert into `users` values(null,?,?)', ['Boby', 35]);
    $batch->queue('insert into `userz` values(null,?,?)', ['Eric', 15]); // 
boom!
    // commit
    $batch->run();
} catch (\Exception $e) {
    print $e->getMessage();
    // rollback & set autocommit=1
    $batch->cancel();
}
// set autocommit=1
$batch->unlock();

// get insert ids if success
foreach ($batch->getResult() as $result) {
    print $result->getId();
}

// remove query queue and empty result array
$batch->reset();

Thanks for replying.

> Wrong HTTP Status Code on Error
> -------------------------------
>
>                 Key: COUCHDB-2910
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-2910
>             Project: CouchDB
>          Issue Type: Bug
>          Components: HTTP Interface
>            Reporter: Kerem Güneş
>
> Hi,
> If I send  a _rev that will cos conflict, server is sending 201 code.
> POST /foo/_bulk_docs? HTTP/1.0
> Host: localhost:5984
> Connection: close
> Accept: application/json
> Content-Type: application/json
> User-Agent: Couch/v1.0.0 (+http://github.com/qeremy/couch-go)
> Content-Length: 126
> {"docs":[{"_id":"7ee9cdd673b109e030cec8c6f10020f7","_rev":"1-WRONG-REV","name":"kerem
>  3","type":"tmp"}]}
> HTTP/1.0 201 Created
> Server: CouchDB/1.5.0 (Erlang OTP/R16B03)
> Date: Thu, 03 Dec 2015 20:11:02 GMT
> Content-Type: application/json
> Content-Length: 100
> Cache-Control: must-revalidate
> [{"id":"7ee9cdd673b109e030cec8c6f10020f7","error":"conflict","reason":"Document
>  update conflict."}]
> Thank you!



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to