Skip to content
Browse files

Better error handling in _bulk_docs

Fixes #200.
  • Loading branch information...
1 parent 4414cb2 commit e8aa48b34806048852468ae84d1471a489a59065 @snej snej committed Dec 31, 2012
Showing with 9 additions and 5 deletions.
  1. +8 −5 Source/TDRouter+Handlers.m
  2. +1 −0 Source/TDStatus.m
View
13 Source/TDRouter+Handlers.m
@@ -295,14 +295,17 @@ - (TDStatus) do_POST_bulk_docs: (TD_Database*)db {
Assert(rev.revID);
if (!noNewEdits)
result = $dict({@"id", rev.docID}, {@"rev", rev.revID}, {@"ok", $true});
+ } else if (status >= 500) {
+ return status; // abort the whole thing if something goes badly wrong
} else if (allOrNothing) {
return status; // all_or_nothing backs out if there's any error
- } else if (status == kTDStatusForbidden) {
- result = $dict({@"id", docID}, {@"error", @"validation failed"});
- } else if (status == kTDStatusConflict) {
- result = $dict({@"id", docID}, {@"error", @"conflict"});
} else {
- return status; // abort the whole thing if something goes badly wrong
+ NSString* error = nil;
+ if (status == kTDStatusForbidden)
+ error = @"validation failed";
+ else
+ TDStatusToHTTPStatus(status, &error);
+ result = $dict({@"id", docID}, {@"error", error});
}
if (result)
[results addObject: result];
View
1 Source/TDStatus.m
@@ -27,6 +27,7 @@
static const struct StatusMapEntry kStatusMap[] = {
{kTDStatusNotFound, 404, "not_found"}, // for compatibility with CouchDB
+ {kTDStatusConflict, 409, "conflict"},
{kTDStatusDuplicate, 412, "Already exists"}, // really 'Precondition Failed'
{kTDStatusBadEncoding, 400, "Bad data encoding"},

0 comments on commit e8aa48b

Please sign in to comment.
Something went wrong with that request. Please try again.