Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make returned error strings more compatible with CouchDB's

These strings are in JSON "error" properties in error responses and in individual items
of a _bulk_docs response.
  • Loading branch information...
commit 9dbed86831f0fe7e16d24eaa0248cfb4bf877375 1 parent 9296c47
@snej snej authored
View
7 Source/TDRouter+Handlers.m
@@ -278,11 +278,8 @@ - (TDStatus) do_POST_bulk_docs: (TD_Database*)db {
return status; // all_or_nothing backs out if there's any error
} else {
NSString* error = nil;
- if (status == kTDStatusForbidden)
- error = @"validation failed";
- else
- TDStatusToHTTPStatus(status, &error);
- result = $dict({@"id", docID}, {@"error", error});
+ status = TDStatusToHTTPStatus(status, &error);
+ result = $dict({@"id", docID}, {@"error", error}, {@"status", @(status)});
}
if (result)
[results addObject: result];
View
2  Source/TDRouter_Tests.m
@@ -119,7 +119,7 @@ static void CheckCacheable(TD_DatabaseManager* server, NSString* path) {
NSDictionary* response = Send(server, @"POST", @"/", kTDStatusBadRequest, nil);
CAssertEqual(response[@"status"], @(400));
- CAssertEqual(response[@"error"], @"bad request");
+ CAssertEqual(response[@"error"], @"bad_request");
NSDictionary* session = Send(server, @"GET", @"/_session", kTDStatusOK, nil);
CAssert(session[@"ok"]);
View
11 Source/TDStatus.m
@@ -26,10 +26,17 @@
};
static const struct StatusMapEntry kStatusMap[] = {
- {kTDStatusNotFound, 404, "not_found"}, // for compatibility with CouchDB
+ // For compatibility with CouchDB, return the same strings it does (see couch_httpd.erl)
+ {kTDStatusBadRequest, 400, "bad_request"},
+ {kTDStatusUnauthorized, 401, "unauthorized"},
+ {kTDStatusNotFound, 404, "not_found"},
+ {kTDStatusForbidden, 403, "forbidden"},
+ {kTDStatusNotAcceptable, 406, "not_acceptable"},
{kTDStatusConflict, 409, "conflict"},
- {kTDStatusDuplicate, 412, "Already exists"}, // really 'Precondition Failed'
+ {kTDStatusDuplicate, 412, "file_exists"}, // really 'Precondition Failed'
+ {kTDStatusUnsupportedType, 415, "bad_content_type"},
+ // These are nonstandard status codes; map them to closest HTTP equivalents:
{kTDStatusBadEncoding, 400, "Bad data encoding"},
{kTDStatusBadAttachment, 400, "Invalid attachment"},
{kTDStatusAttachmentNotFound, 404, "Attachment not found"},
Please sign in to comment.
Something went wrong with that request. Please try again.