CppCrate 0.1
Public Member Functions | List of all members
CppCrate::RawResult Class Reference

Public Member Functions

 RawResult ()
 
 RawResult (int code)
 
 RawResult (const std::string &reply)
 
 RawResult (const std::string &reply, int code)
 
bool hasError () const
 
int httpStatusCode () const
 
bool isEmpty () const
 
 operator bool () const
 
const std::string & reply () const
 
void setHttpStatusCode (int code)
 
void setReply (const std::string &reply)
 

Detailed Description

The class RawResult encapsulates the plain reply of a Crate HTTP endpoint request. It consists only of two information: the HTTP status code and the server's reply.

The reply is typically the JSON data received from the endpoint. In case the cluster could not be reached due to network problems this error is also wrapped in a Crate like error. In addition, however, the object is extended by the key "component" with the value "curl":

{
"error" :
{
"message" : "Protocol \"httx\" not supported or disabled in libcurl",
"code" : 1,
"component" : "curl"
}
}
See also
Result

Constructor & Destructor Documentation

◆ RawResult() [1/4]

CppCrate::RawResult::RawResult ( )

Constructs an empty result.

◆ RawResult() [2/4]

CppCrate::RawResult::RawResult ( int  code)
explicit

Constructs a result with the HTTP status code code.

◆ RawResult() [3/4]

CppCrate::RawResult::RawResult ( const std::string &  reply)
explicit

Constructs a result with the reply reply.

◆ RawResult() [4/4]

CppCrate::RawResult::RawResult ( const std::string &  reply,
int  code 
)

Constructs a result with the reply reply and the HTTP status code code.

Member Function Documentation

◆ hasError()

bool CppCrate::RawResult::hasError ( ) const

Returns whether the reply contains an error. An empty reply or ill formed JSON are considered erroneous. For bulk operations true is returned if at least one operation failed.

Note
This function parses the reply so you might cache the result if it's needed more than once.

◆ httpStatusCode()

int CppCrate::RawResult::httpStatusCode ( ) const

Returns the HTTP status code.

◆ isEmpty()

bool CppCrate::RawResult::isEmpty ( ) const

Returns whether the result is empty.

◆ operator bool()

CppCrate::RawResult::operator bool ( ) const
explicit

Returns whether the reply contains an error.

See also
hasError()

◆ reply()

const std::string & CppCrate::RawResult::reply ( ) const

Returns the server's reply.

◆ setHttpStatusCode()

void CppCrate::RawResult::setHttpStatusCode ( int  code)

Sets the HTTP status code to code.

◆ setReply()

void CppCrate::RawResult::setReply ( const std::string &  reply)

Sets the reply to reply.