Skip to content

Commit

Permalink
exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
flashnuke committed Sep 27, 2021
1 parent 3b41af6 commit cb0df7b
Showing 2 changed files with 6 additions and 10 deletions.
4 changes: 2 additions & 2 deletions include/Client_Exceptions.h
Original file line number Diff line number Diff line change
@@ -17,13 +17,13 @@ class ClientException : public std::exception

// REST Client Exceptions

class BadSetupSessionREST : public ClientException // for bad REST requests
class BadSetupSessionREST : public ClientException
{
public:
BadSetupSessionREST();
};

class BadRequestREST : public ClientException // for trying methods where auth is needed but keys are missing
class BadRequestREST : public ClientException
{
public:
BadRequestREST();
12 changes: 4 additions & 8 deletions src/REST_Client.cpp
Original file line number Diff line number Diff line change
@@ -63,35 +63,31 @@ RestSession::RestSession() // except handles in rest_init exchange client level
curl_easy_setopt(this->_get_handle, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(this->_get_handle, CURLOPT_WRITEFUNCTION, _REQ_CALLBACK);
curl_easy_setopt(this->_get_handle, CURLOPT_FAILONERROR, 0);

if (!(this->_get_handle)) throw("BAD_GET_SETUP");

_post_handle = curl_easy_init();
curl_easy_setopt(this->_post_handle, CURLOPT_POST, 1L);
curl_easy_setopt(this->_post_handle, CURLOPT_POSTFIELDSIZE, 0);
curl_easy_setopt(this->_post_handle, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(this->_post_handle, CURLOPT_WRITEFUNCTION, _REQ_CALLBACK);
curl_easy_setopt(this->_post_handle, CURLOPT_FAILONERROR, 0);
if (!(this->_post_handle)) throw("BAD_POST_SETUP"); // handle exc

_put_handle = curl_easy_init();
curl_easy_setopt(this->_put_handle, CURLOPT_UPLOAD, 1L);
curl_easy_setopt(this->_put_handle, CURLOPT_INFILESIZE, 0);
curl_easy_setopt(this->_put_handle, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(this->_put_handle, CURLOPT_WRITEFUNCTION, _REQ_CALLBACK);
curl_easy_setopt(this->_put_handle, CURLOPT_FAILONERROR, 0);
if (!(this->_put_handle)) throw("BAD_PUT_SETUP"); // handle exc

_delete_handle = curl_easy_init();
curl_easy_setopt(this->_delete_handle, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_easy_setopt(this->_delete_handle, CURLOPT_POSTFIELDSIZE, 0);
curl_easy_setopt(this->_delete_handle, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(this->_delete_handle, CURLOPT_WRITEFUNCTION, _REQ_CALLBACK);
curl_easy_setopt(this->_delete_handle, CURLOPT_FAILONERROR, 0);


if (!(this->_get_handle)) throw("exc"); // handle exc
if (!(this->_post_handle)) throw("exc"); // handle exc
if (!(this->_put_handle)) throw("exc"); // handle exc
if (!(this->_delete_handle)) throw("exc"); // handle exc

if (!(this->_delete_handle)) throw("BAD_DELETE_SETUP"); // handle exc

this->status = 1;
}

0 comments on commit cb0df7b

Please sign in to comment.