Discord Social SDK
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
discordpp::ClientResult Class Reference

Detailed Description

Struct that stores information about the result of an SDK function call.

Functions can fail for a few reasons including:

  • The Client is not yet ready and able to perform the action.
  • The inputs passed to the function are invalid.
  • The function makes an API call to Discord's backend which returns an error.
  • The user is offline.

The ClientResult::Type field is used to to distinguish between the above types of failures

Public Member Functions

 ClientResult (ClientResult &&other) noexcept
 Move constructor for ClientResult.
 
ClientResultoperator= (ClientResult &&other) noexcept
 Move assignment operator for ClientResult.
 
 operator bool () const
 Returns true if the instance contains a valid object.
 
 ClientResult (const ClientResult &arg0)
 Copy constructor for ClientResult.
 
ClientResultoperator= (const ClientResult &arg0)
 Copy assignment operator for ClientResult.
 
std::string ToString () const
 Returns the error message if any of the ClientResult.
 
discordpp::ErrorType Type () const
 The type of error that occurred. See ErrorType for more information.
 
void SetType (discordpp::ErrorType Type)
 Setter for ClientResult::Type.
 
std::string Error () const
 A description of the error that occurred.
 
void SetError (std::string Error)
 Setter for ClientResult::Error.
 
int32_t ErrorCode () const
 A more detailed error code for this failure. Currently the only use of this is when an API request is made to Discord's backend and that fails with a specific error, that error will be included in this field.
 
void SetErrorCode (int32_t ErrorCode)
 Setter for ClientResult::ErrorCode.
 
discordpp::HttpStatusCode Status () const
 The HTTP status code of the API call.
 
void SetStatus (discordpp::HttpStatusCode Status)
 Setter for ClientResult::Status.
 
std::string ResponseBody () const
 The full HTTP response body, which will usually be a JSON string.
 
void SetResponseBody (std::string ResponseBody)
 Setter for ClientResult::ResponseBody.
 
bool Successful () const
 Equivalent to type == ErrorType::None.
 
void SetSuccessful (bool Successful)
 Setter for ClientResult::Successful.
 
bool Retryable () const
 Indicates if, although an API request failed, it is safe and recommended to retry it.
 
void SetRetryable (bool Retryable)
 Setter for ClientResult::Retryable.
 
float RetryAfter () const
 When a user is being rate limited by Discord (and so status == 429), this field should be set and is the number of seconds to wait before trying again.
 
void SetRetryAfter (float RetryAfter)
 Setter for ClientResult::RetryAfter.
 

Static Public Attributes

static const ClientResult nullobj
 Uninitialized instance of ClientResult.
 

Constructor & Destructor Documentation

◆ ClientResult() [1/2]

discordpp::ClientResult::ClientResult ( ClientResult && other)
noexcept

Move constructor for ClientResult.

◆ ClientResult() [2/2]

discordpp::ClientResult::ClientResult ( const ClientResult & arg0)

Copy constructor for ClientResult.

Member Function Documentation

◆ Error()

std::string discordpp::ClientResult::Error ( ) const

A description of the error that occurred.

◆ ErrorCode()

int32_t discordpp::ClientResult::ErrorCode ( ) const

A more detailed error code for this failure. Currently the only use of this is when an API request is made to Discord's backend and that fails with a specific error, that error will be included in this field.

Many of these error codes are documented at: https://discord.com/developers/docs/topics/opcodes-and-status-codes#json

This will only be set if the type of error is ErrorType::HTTPError

◆ operator bool()

discordpp::ClientResult::operator bool ( ) const
inline

Returns true if the instance contains a valid object.

◆ operator=() [1/2]

ClientResult & discordpp::ClientResult::operator= ( ClientResult && other)
noexcept

Move assignment operator for ClientResult.

◆ operator=() [2/2]

ClientResult & discordpp::ClientResult::operator= ( const ClientResult & arg0)

Copy assignment operator for ClientResult.

◆ ResponseBody()

std::string discordpp::ClientResult::ResponseBody ( ) const

The full HTTP response body, which will usually be a JSON string.

The error format here is a bit more complicated because Discord's API tries to make it clear which field from the request is causing the error. Documentation on the format of these errors is here: https://discord.com/developers/docs/reference#error-messages

This will only be set if the type of error is ErrorType::HTTPError

◆ Retryable()

bool discordpp::ClientResult::Retryable ( ) const

Indicates if, although an API request failed, it is safe and recommended to retry it.

◆ RetryAfter()

float discordpp::ClientResult::RetryAfter ( ) const

When a user is being rate limited by Discord (and so status == 429), this field should be set and is the number of seconds to wait before trying again.

◆ SetError()

void discordpp::ClientResult::SetError ( std::string Error)

Setter for ClientResult::Error.

◆ SetErrorCode()

void discordpp::ClientResult::SetErrorCode ( int32_t ErrorCode)

◆ SetResponseBody()

void discordpp::ClientResult::SetResponseBody ( std::string ResponseBody)

◆ SetRetryable()

void discordpp::ClientResult::SetRetryable ( bool Retryable)

◆ SetRetryAfter()

void discordpp::ClientResult::SetRetryAfter ( float RetryAfter)

◆ SetStatus()

void discordpp::ClientResult::SetStatus ( discordpp::HttpStatusCode Status)

Setter for ClientResult::Status.

◆ SetSuccessful()

void discordpp::ClientResult::SetSuccessful ( bool Successful)

◆ SetType()

void discordpp::ClientResult::SetType ( discordpp::ErrorType Type)

Setter for ClientResult::Type.

◆ Status()

discordpp::HttpStatusCode discordpp::ClientResult::Status ( ) const

The HTTP status code of the API call.

This will only be set if the type of error is ErrorType::HTTPError

◆ Successful()

bool discordpp::ClientResult::Successful ( ) const

Equivalent to type == ErrorType::None.

◆ ToString()

std::string discordpp::ClientResult::ToString ( ) const

Returns the error message if any of the ClientResult.

◆ Type()

discordpp::ErrorType discordpp::ClientResult::Type ( ) const

The type of error that occurred. See ErrorType for more information.

Member Data Documentation

◆ nullobj

const ClientResult discordpp::ClientResult::nullobj
static

Uninitialized instance of ClientResult.