Skip to content
Browse files

Better error if a pushed document fails to be saved

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...
1 parent 399d477 commit dee1afe553a5c1b78289aee9c92cd7fc3b9b6324 @snej snej committed Nov 14, 2012
Showing with 7 additions and 1 deletion.
  1. +6 −1 Source/TDPusher.m
  2. +1 −0 Source/TDStatus.h
View
7 Source/TDPusher.m
@@ -254,7 +254,12 @@ - (void) uploadBulkDocs: (NSArray*)docsToSend
if (item[@"error"]) {
// One of the docs failed to save:
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);
}
}
}
View
1 Source/TDStatus.h
@@ -16,6 +16,7 @@ typedef enum {
kTDStatusNotModified = 304,
kTDStatusBadRequest = 400,
+ kTDStatusUnauthorized = 401,
kTDStatusForbidden = 403,
kTDStatusNotFound = 404,
kTDStatusNotAcceptable = 406,

0 comments on commit dee1afe

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