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

Commit

Permalink
Better error if a pushed document fails to be saved
Browse files Browse the repository at this point in the history
If remote _bulk_docs indicates an error saving a document,
(a) Map "unauthorized" message to 401 status (instead of default 502)
(b) Put the document's URL in the NSError object's userInfo.
  • Loading branch information
snej committed Nov 14, 2012
1 parent 399d477 commit dee1afe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Source/TDPusher.m
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -254,7 +254,12 @@ - (void) uploadBulkDocs: (NSArray*)docsToSend
if (item[@"error"]) { if (item[@"error"]) {
// One of the docs failed to save: // One of the docs failed to save:
Warn(@"%@: _bulk_docs got an error: %@", self, item); Warn(@"%@: _bulk_docs got an error: %@", self, item);
error = TDStatusToNSError(kTDStatusUpstreamError, nil); TDStatus status = kTDStatusUpstreamError;
if ($equal(item[@"error"], @"unauthorized"))
status = kTDStatusUnauthorized;
NSString* docID = item[@"id"];
NSURL* url = docID ? [_remote URLByAppendingPathComponent: docID] : nil;
error = TDStatusToNSError(status, url);
} }
} }
} }
Expand Down
1 change: 1 addition & 0 deletions Source/TDStatus.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ typedef enum {
kTDStatusNotModified = 304, kTDStatusNotModified = 304,


kTDStatusBadRequest = 400, kTDStatusBadRequest = 400,
kTDStatusUnauthorized = 401,
kTDStatusForbidden = 403, kTDStatusForbidden = 403,
kTDStatusNotFound = 404, kTDStatusNotFound = 404,
kTDStatusNotAcceptable = 406, kTDStatusNotAcceptable = 406,
Expand Down

0 comments on commit dee1afe

Please sign in to comment.