Change api error structure
This commit is contained in:
@@ -43,10 +43,11 @@ protected:
|
||||
class SIADRIVE_EXPORTABLE CSiaApi
|
||||
{
|
||||
public:
|
||||
enum class _SiaApiError
|
||||
enum class _SiaApiErrorCode
|
||||
{
|
||||
Success,
|
||||
NotImplemented,
|
||||
NotConnected,
|
||||
RequestError,
|
||||
WalletExists,
|
||||
WalletLocked,
|
||||
@@ -133,10 +134,10 @@ public:
|
||||
virtual void Refresh(const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig);
|
||||
|
||||
public:
|
||||
_SiaApiError Create(const _SiaSeedLanguage& seedLanguage, SString& seed);
|
||||
_SiaApiError Restore(const SString& seed);
|
||||
_SiaApiError Lock();
|
||||
_SiaApiError Unlock(const SString& password);
|
||||
CSiaError<_SiaApiErrorCode> Create(const _SiaSeedLanguage& seedLanguage, SString& seed);
|
||||
CSiaError<_SiaApiErrorCode> Restore(const SString& seed);
|
||||
CSiaError<_SiaApiErrorCode> Lock();
|
||||
CSiaError<_SiaApiErrorCode> Unlock(const SString& password);
|
||||
};
|
||||
|
||||
class SIADRIVE_EXPORTABLE _CSiaRenter :
|
||||
@@ -176,12 +177,12 @@ public:
|
||||
void Refresh(const CSiaCurl& siaCurl, CSiaDriveConfig* siaDriveConfig);
|
||||
|
||||
public:
|
||||
_SiaApiError FileExists(const SString& siaPath, bool& exists) const;
|
||||
_SiaApiError DownloadFile(const SString& siaPath, const SString& location) const;
|
||||
_SiaApiError GetFileTree(std::shared_ptr<_CSiaFileTree>& siaFileTree) const;
|
||||
CSiaError<_SiaApiErrorCode> FileExists(const SString& siaPath, bool& exists) const;
|
||||
CSiaError<_SiaApiErrorCode> DownloadFile(const SString& siaPath, const SString& location) const;
|
||||
CSiaError<_SiaApiErrorCode> GetFileTree(std::shared_ptr<_CSiaFileTree>& siaFileTree) const;
|
||||
_SiaRenterAllowance GetAllowance() const;
|
||||
_SiaApiError SetAllowance(const _SiaRenterAllowance& renterAllowance);
|
||||
_SiaApiError RefreshFileTree( );
|
||||
CSiaError<_SiaApiErrorCode> SetAllowance(const _SiaRenterAllowance& renterAllowance);
|
||||
CSiaError<_SiaApiErrorCode> RefreshFileTree( );
|
||||
};
|
||||
|
||||
class SIADRIVE_EXPORTABLE _CSiaConsensus :
|
||||
@@ -233,7 +234,8 @@ public:
|
||||
SiaHostConfig GetHostConfig() const;
|
||||
};
|
||||
|
||||
typedef CSiaApi::_SiaApiError SiaApiError;
|
||||
typedef CSiaApi::_SiaApiErrorCode SiaApiErrorCode;
|
||||
typedef CSiaError<SiaApiErrorCode> SiaApiError;
|
||||
typedef CSiaApi::_SiaSeedLanguage SiaSeedLanguage;
|
||||
typedef CSiaApi::_CSiaWallet CSiaWallet;
|
||||
typedef CSiaApi::_CSiaRenter CSiaRenter;
|
||||
|
@@ -98,6 +98,36 @@ get_access:\
|
||||
set_access:\
|
||||
type Set##name(const type& value) { json_doc[#name] = value; return value; }
|
||||
|
||||
template<typename T>
|
||||
class CSiaError
|
||||
{
|
||||
public:
|
||||
CSiaError()
|
||||
{
|
||||
SetCode(T::Success);
|
||||
}
|
||||
|
||||
CSiaError(const T& t)
|
||||
{
|
||||
SetCode(t);
|
||||
}
|
||||
|
||||
CSiaError(const T& code, const SString& reason)
|
||||
{
|
||||
SetCode(code);
|
||||
SetReason(reason);
|
||||
}
|
||||
|
||||
public:
|
||||
Property(T, Code, public, private)
|
||||
Property(SString, Reason, public, private)
|
||||
|
||||
public:
|
||||
operator bool() { return GetCode() == T::Success; }
|
||||
operator bool() const { return GetCode() == T::Success; }
|
||||
CSiaError& operator=(const T& code) { SetCode(code); return *this; }
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SString HostName;
|
||||
@@ -107,7 +137,7 @@ typedef struct
|
||||
|
||||
template<typename T>
|
||||
inline bool ApiSuccess(const T& t) {
|
||||
return t == T::Success;
|
||||
return static_cast<bool>(t);
|
||||
}
|
||||
|
||||
typedef ttmath::UInt<256> Hastings;
|
||||
|
@@ -9,7 +9,7 @@ NS_BEGIN(Api)
|
||||
class SIADRIVE_EXPORTABLE CSiaCurl
|
||||
{
|
||||
public:
|
||||
enum class _SiaCurlError
|
||||
enum class _SiaCurlErrorCode
|
||||
{
|
||||
Success,
|
||||
ServerVersionMismatch,
|
||||
@@ -36,23 +36,23 @@ public:
|
||||
static SString UrlEncode(const SString& data, const bool& allowSlash = false);
|
||||
|
||||
private:
|
||||
static _SiaCurlError CheckApiError(const json& result);
|
||||
static _SiaCurlError CheckHttpError(const std::string& result);
|
||||
static SString CSiaCurl::GetApiErrorMessage(const json& result);
|
||||
|
||||
private:
|
||||
std::string ConstructPath(const SString& relativePath) const;
|
||||
_SiaCurlError _Get(const SString& path, const _HttpParameters& parameters, json& response) const;
|
||||
bool CheckVersion(_SiaCurlError& error) const;
|
||||
_SiaCurlError ProcessResponse(const int& res, const int& httpCode, const std::string& result, json& response) const;
|
||||
CSiaError<_SiaCurlErrorCode> _Get(const SString& path, const _HttpParameters& parameters, json& response) const;
|
||||
bool CheckVersion(CSiaError<_SiaCurlErrorCode>& error) const;
|
||||
CSiaError<_SiaCurlErrorCode> ProcessResponse(const int& res, const int& httpCode, const std::string& result, json& response) const;
|
||||
|
||||
public:
|
||||
SString GetServerVersion() const;
|
||||
_SiaCurlError Get(const SString& path, json& result) const;
|
||||
_SiaCurlError Get(const SString& path, const _HttpParameters& parameters, json& result) const;
|
||||
_SiaCurlError Post(const SString& path, const _HttpParameters& parameters, json& response) const;
|
||||
CSiaError<_SiaCurlErrorCode> Get(const SString& path, json& result) const;
|
||||
CSiaError<_SiaCurlErrorCode> Get(const SString& path, const _HttpParameters& parameters, json& result) const;
|
||||
CSiaError<_SiaCurlErrorCode> Post(const SString& path, const _HttpParameters& parameters, json& response) const;
|
||||
};
|
||||
|
||||
typedef CSiaCurl::_SiaCurlError SiaCurlError;
|
||||
typedef CSiaCurl::_SiaCurlErrorCode SiaCurlErrorCode;
|
||||
typedef CSiaError<SiaCurlErrorCode> SiaCurlError;
|
||||
typedef CSiaCurl::_HttpParameters HttpParameters;
|
||||
|
||||
NS_END(2)
|
||||
|
@@ -26,7 +26,7 @@ public:
|
||||
Error
|
||||
};
|
||||
|
||||
enum class _UploadError
|
||||
enum class _UploadErrorCode
|
||||
{
|
||||
Success,
|
||||
SourceFileNotFound,
|
||||
@@ -68,12 +68,13 @@ public:
|
||||
|
||||
public:
|
||||
_UploadStatus GetUploadStatus(const SString& siaPath);
|
||||
_UploadError AddOrUpdate(const SString& siaPath, SString filePath);
|
||||
_UploadError Remove(const SString& siaPath);
|
||||
CSiaError<_UploadErrorCode> AddOrUpdate(const SString& siaPath, SString filePath);
|
||||
CSiaError<_UploadErrorCode> Remove(const SString& siaPath);
|
||||
};
|
||||
|
||||
typedef Sia::Api::CUploadManager::_UploadStatus UploadStatus;
|
||||
typedef Sia::Api::CUploadManager::_UploadError UploadError;
|
||||
typedef CUploadManager::_UploadStatus UploadStatus;
|
||||
typedef CUploadManager::_UploadErrorCode UploadErrorCode;
|
||||
typedef CSiaError<CUploadManager::_UploadErrorCode> UploadError;
|
||||
|
||||
// Event Notifications
|
||||
class CreatingTemporarySiaDriveFile :
|
||||
@@ -388,7 +389,7 @@ public:
|
||||
private:
|
||||
const SString _siaPath;
|
||||
const SString _filePath;
|
||||
const SiaCurlError _curlError = SiaCurlError::Success;
|
||||
const SiaCurlError _curlError;
|
||||
|
||||
public:
|
||||
virtual SString GetSingleLineMessage() const override
|
||||
|
Reference in New Issue
Block a user