Loading...
Searching...
No Matches
HueException.h
Go to the documentation of this file.
#ifndef INCLUDE_HUEPLUSPLUS_HUE_EXCEPTION_H
#define INCLUDE_HUEPLUSPLUS_HUE_EXCEPTION_H
#include <exception>
#include <string>
#include <nlohmann/json.hpp>
namespace hueplusplus
{
struct FileInfo
{
std::string filename;
int line = -1;
std::string func;
std::string ToString() const;
};
class HueException : public std::exception
{
public:
HueException(FileInfo fileInfo, const std::string& message);
const char* what() const noexcept override;
const FileInfo& GetFile() const noexcept;
protected:
HueException(const char* exceptionName, FileInfo fileInfo, const std::string& message);
private:
std::string whatMessage;
FileInfo fileInfo;
};
class HueAPIResponseException : public HueException
{
public:
HueAPIResponseException(FileInfo fileInfo, int error, std::string address, std::string description);
int GetErrorNumber() const noexcept;
const std::string& GetAddress() const noexcept;
const std::string& GetDescription() const noexcept;
static HueAPIResponseException Create(FileInfo fileInfo, const nlohmann::json& response);
private:
static std::string GetMessage(int error, const std::string& addr, const std::string& description);
private:
int error;
std::string address;
std::string description;
};
} // namespace hueplusplus
#endif
hueplusplus::HueAPIResponseException::GetAddress
const std::string & GetAddress() const noexcept
Address the API call tried to access.
Definition HueException.cpp:64
hueplusplus::HueAPIResponseException::HueAPIResponseException
HueAPIResponseException(FileInfo fileInfo, int error, std::string address, std::string description)
Create exception with info from Hue API error.
Definition HueException.cpp:51
hueplusplus::HueAPIResponseException::GetDescription
const std::string & GetDescription() const noexcept
Error description.
Definition HueException.cpp:69
hueplusplus::HueAPIResponseException::Create
static HueAPIResponseException Create(FileInfo fileInfo, const nlohmann::json &response)
Creates exception from API response.
Definition HueException.cpp:74
hueplusplus::HueAPIResponseException::GetErrorNumber
int GetErrorNumber() const noexcept
Error number from Hue API error response.
Definition HueException.cpp:59
hueplusplus::HueException::GetFile
const FileInfo & GetFile() const noexcept
Filename and line where the exception was thrown or caused by.
Definition HueException.cpp:36
hueplusplus::HueException::HueException
HueException(FileInfo fileInfo, const std::string &message)
Creates HueException with information about the error and source.
Definition HueException.cpp:27
hueplusplus::HueException::what
const char * what() const noexcept override
What message of the exception.
Definition HueException.cpp:31
hueplusplus
Namespace for the hueplusplus library.
Definition Action.h:28
hueplusplus::FileInfo
Contains information about error location, use CURRENT_FILE_INFO to create.
Definition HueException.h:35
hueplusplus::FileInfo::filename
std::string filename
Current file name from FILE. Empty if unknown.
Definition HueException.h:37
hueplusplus::FileInfo::line
int line
Current line number from LINE. -1 if unknown.
Definition HueException.h:39
hueplusplus::FileInfo::func
std::string func
Current function from func. Empty if unknown.
Definition HueException.h:41
hueplusplus::FileInfo::ToString
std::string ToString() const
String representation of func, file and line.
Definition HueException.cpp:104