expectSingle method
Returns the single JSON object in the response body.
Throws an AssertionError if the response body is null or not a single object.
Implementation
JSON expectSingle() {
assert(isOk,
"Response does not indicate success (status code: $statusCode). This should not happen. Try to call isOk and implement your own custom error handling before calling this method.");
if (body == null) {
throw AssertionError("Response body is null");
}
if (body!.isLeft) {
throw AssertionError("Expected single object, got array");
}
return body!.right;
}