1
0

Get http error code from curl

This commit is contained in:
Scott E. Graves
2017-02-22 14:40:46 -06:00
parent 49224162f2
commit 9eb050a141
3 changed files with 12 additions and 6 deletions

View File

@@ -56,10 +56,10 @@ SiaCurlError CSiaCurl::CheckHttpError(const std::string& result)
return SiaCurlError::Success; return SiaCurlError::Success;
} }
SiaCurlError CSiaCurl::ProcessResponse(const int& res, const std::string& result, json& response) const SiaCurlError CSiaCurl::ProcessResponse(const int& res, const int& httpCode, const std::string& result, json& response) const
{ {
SiaCurlError ret; SiaCurlError ret;
if (res == CURLE_OK) if ((res == CURLE_OK) && (httpCode == 200))
{ {
ret = CheckHttpError(result); ret = CheckHttpError(result);
if (ApiSuccess(ret)) if (ApiSuccess(ret))
@@ -98,7 +98,10 @@ SiaCurlError CSiaCurl::_Get(const String& path, json& response) const
curl_easy_setopt(_curlHandle, CURLOPT_WRITEDATA, &result); curl_easy_setopt(_curlHandle, CURLOPT_WRITEDATA, &result);
const CURLcode res = curl_easy_perform(_curlHandle); const CURLcode res = curl_easy_perform(_curlHandle);
return ProcessResponse(res, result, response); long httpCode = 0;
curl_easy_getinfo(_curlHandle, CURLINFO_RESPONSE_CODE, &httpCode);
return ProcessResponse(res, httpCode, result, response);
} }
bool CSiaCurl::CheckVersion(SiaCurlError& error) const bool CSiaCurl::CheckVersion(SiaCurlError& error) const
@@ -170,7 +173,10 @@ SiaCurlError CSiaCurl::Post(const String& path, const PostParameters& parameters
curl_easy_setopt(_curlHandle, CURLOPT_WRITEDATA, &result); curl_easy_setopt(_curlHandle, CURLOPT_WRITEDATA, &result);
const CURLcode res = curl_easy_perform(_curlHandle); const CURLcode res = curl_easy_perform(_curlHandle);
ret = ProcessResponse(res, result, response); long httpCode = 0;
curl_easy_getinfo(_curlHandle, CURLINFO_RESPONSE_CODE, &httpCode);
ret = ProcessResponse(res, httpCode, result, response);
} }
return ret; return ret;

View File

@@ -42,7 +42,7 @@ private:
std::string ConstructPath(const String& relativePath) const; std::string ConstructPath(const String& relativePath) const;
_SiaCurlError _Get(const String& path, json& response) const; _SiaCurlError _Get(const String& path, json& response) const;
bool CheckVersion(_SiaCurlError& error) const; bool CheckVersion(_SiaCurlError& error) const;
_SiaCurlError ProcessResponse(const int& res, const std::string& result, json& response) const; _SiaCurlError ProcessResponse(const int& res, const int& httpCode, const std::string& result, json& response) const;
public: public:
String GetServerVersion() const; String GetServerVersion() const;

View File

@@ -23,7 +23,7 @@ wept saxophone dialect depth update jaunt loincloth asleep lush gnome laptop upp
* Work Test * Work Test
names amaze when afraid inmate hull hexagon etched niece rudely tudor unopened acidic swagger emit shrugged noises tycoon leech tubes shrugged bulb inexact plywood tuesday rims cease excess aces names amaze when afraid inmate hull hexagon etched niece rudely tudor unopened acidic swagger emit shrugged noises tycoon leech tubes shrugged bulb inexact plywood tuesday rims cease excess aces
* Work Test2 * Work Test2
ornament alkaline gasp pepper upkeep ablaze number sizes toyed sawmill looking bygones dwarf nerves session cake jerseys niche arrow howls omission verification identity waffle pockets giving hiding river acoustic ornament alkaline gasp pepper upkeep ablaze number sizes toyed sawmill looking bygones dwarf nerves session cake jerseys niche arrow howls omission verification identity waffle pockets giving hiding river acoustic
*/ */