Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
Better error handling in _bulk_docs
Browse files Browse the repository at this point in the history
Fixes #200.
  • Loading branch information
snej committed Jan 1, 2013
1 parent 4414cb2 commit e8aa48b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
13 changes: 8 additions & 5 deletions Source/TDRouter+Handlers.m
Expand Up @@ -295,14 +295,17 @@ - (TDStatus) do_POST_bulk_docs: (TD_Database*)db {
Assert(rev.revID); Assert(rev.revID);
if (!noNewEdits) if (!noNewEdits)
result = $dict({@"id", rev.docID}, {@"rev", rev.revID}, {@"ok", $true}); 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) { } else if (allOrNothing) {
return status; // all_or_nothing backs out if there's any error 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 { } 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) if (result)
[results addObject: result]; [results addObject: result];
Expand Down
1 change: 1 addition & 0 deletions Source/TDStatus.m
Expand Up @@ -27,6 +27,7 @@


static const struct StatusMapEntry kStatusMap[] = { static const struct StatusMapEntry kStatusMap[] = {
{kTDStatusNotFound, 404, "not_found"}, // for compatibility with CouchDB {kTDStatusNotFound, 404, "not_found"}, // for compatibility with CouchDB
{kTDStatusConflict, 409, "conflict"},
{kTDStatusDuplicate, 412, "Already exists"}, // really 'Precondition Failed' {kTDStatusDuplicate, 412, "Already exists"}, // really 'Precondition Failed'


{kTDStatusBadEncoding, 400, "Bad data encoding"}, {kTDStatusBadEncoding, 400, "Bad data encoding"},
Expand Down

0 comments on commit e8aa48b

Please sign in to comment.