Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions Networking/HTTP/HTTPLogic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "Error.hh"
#include "SecureRandomize.hh"
#include "SecureDigest.hh"
#include "StringUtil.hh"
#include "slice_stream.hh"
#include "NumConversion.hh"
#include "fleece/Fleece.hh"
Expand Down Expand Up @@ -351,12 +352,19 @@ namespace litecore::net {
Disposition disposition = receivedResponse(response);
if ( disposition == kFailure && _error.domain == WebSocketDomain && _error.code == int(_httpStatus) ) {
// Look for a more detailed HTTP error message in the response body:
if ( _responseHeaders["Content-Type"_sl].hasPrefix("application/json"_sl) ) {
alloc_slice responseBody;
if ( socket.readHTTPBody(_responseHeaders, responseBody) ) {
Doc json = Doc::fromJSON(responseBody);
if ( slice reason = json["reason"].asString(); reason )
_error = c4error_make(WebSocketDomain, int(_httpStatus), reason);
if ( bool isJSON = _responseHeaders["Content-Type"_sl].hasPrefix("application/json"_sl);
isJSON || _responseHeaders["Content-Type"_sl].hasPrefix("text/plain"_sl) ) {
if ( alloc_slice responseBody; socket.readHTTPBody(_responseHeaders, responseBody) ) {
slice reason;
Doc json;
if ( isJSON ) {
json = Doc::fromJSON(responseBody);
reason = json["reason"].asString();
} else { // text/plain
// trimming the ending '\n's
reason = trimWhitespace(responseBody);
}
_error = c4error_make(WebSocketDomain, int(_httpStatus), (slice)reason);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Replicator/tests/ReplicatorCollectionSGTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ TEST_CASE_METHOD(ReplicatorCollectionSGTest, "Bad Configurations SG", "[.SyncSer
for ( auto& coll : _collections ) { importJSONLines(sFixturesDir + "names_100.json", coll, 0, false, 2, idPrefix); }
ReplParams replParams{_collectionSpecs};

C4Error expectedError;
C4Error expectedError{};
slice expectedErrorMsg;

SECTION("Mixed OneShot and Continuous Modes") {
Expand Down