Skip to content

Commit 0185451

Browse files
committed
sanity check for impl
1 parent 763df97 commit 0185451

1 file changed

Lines changed: 45 additions & 3 deletions

File tree

source/gameanalytics/GAHTTPApi.cpp

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ namespace gameanalytics
2727
GAHTTPApi::GAHTTPApi():
2828
impl(std::make_unique<GAHttpCurl>())
2929
{
30-
impl->initialize();
30+
if(impl)
31+
{
32+
impl->initialize();
33+
}
3134

3235
baseUrl = protocol + "://" + hostName + "/" + version;
3336
remoteConfigsBaseUrl = protocol + "://" + hostName + "/remote_configs/" + remoteConfigsVersion;
@@ -42,7 +45,10 @@ namespace gameanalytics
4245

4346
GAHTTPApi::~GAHTTPApi()
4447
{
45-
impl->cleanup();
48+
if(impl)
49+
{
50+
impl->cleanup();
51+
}
4652
}
4753

4854
GAHTTPApi& GAHTTPApi::getInstance()
@@ -52,6 +58,12 @@ namespace gameanalytics
5258

5359
EGAHTTPApiResponse GAHTTPApi::requestInitReturningDict(json& json_out, std::string const& configsHash)
5460
{
61+
if(!impl)
62+
{
63+
logging::GALogger::e("Invalid http implmentation");
64+
return SdkError;
65+
}
66+
5567
std::string gameKey = state::GAState::getGameKey();
5668

5769
// Generate URL
@@ -75,6 +87,12 @@ namespace gameanalytics
7587
std::string const auth = createAuth(payloadData);
7688
GAHttpWrapper::Response response = impl->sendRequest(url, auth, payloadData, useGzip, nullptr);
7789

90+
if(response.code < 0)
91+
{
92+
logging::GALogger::e("Request failed: %s", url.c_str());
93+
return;
94+
}
95+
7896
std::string_view content = response.toString();
7997

8098
// process the response
@@ -143,6 +161,12 @@ namespace gameanalytics
143161

144162
EGAHTTPApiResponse GAHTTPApi::sendEventsInArray(json& json_out, const json& eventArray)
145163
{
164+
if(!impl)
165+
{
166+
logging::GALogger::e("Invalid http implmentation");
167+
return SdkError;
168+
}
169+
146170
if (eventArray.empty())
147171
{
148172
logging::GALogger::d("sendEventsInArray called with missing eventArray");
@@ -169,6 +193,12 @@ namespace gameanalytics
169193
std::string const auth = createAuth(payloadData);
170194
GAHttpWrapper::Response response = impl->sendRequest(url, auth, payloadData, useGzip, nullptr);
171195

196+
if(response.code < 0)
197+
{
198+
logging::GALogger::e("Request failed: %s", url.c_str());
199+
return;
200+
}
201+
172202
std::string_view content = response.toString();
173203
logging::GALogger::d("body: %.*s", (int)content.size(), content.data());
174204

@@ -224,6 +254,12 @@ namespace gameanalytics
224254

225255
void GAHTTPApi::sendSdkErrorEvent(EGASdkErrorCategory category, EGASdkErrorArea area, EGASdkErrorAction action, EGASdkErrorParameter parameter, std::string const& reason, std::string const& gameKey, const std::string& secretKey)
226256
{
257+
if(!impl)
258+
{
259+
logging::GALogger::e("Invalid http implmentation");
260+
return;
261+
}
262+
227263
if(!state::GAState::isEventSubmissionEnabled())
228264
{
229265
return;
@@ -250,7 +286,7 @@ namespace gameanalytics
250286
utilities::addIfNotEmpty(jsonObject, "error_parameter", sdkErrorParameterString(parameter));
251287
utilities::addIfNotEmpty(jsonObject, "reason", reason);
252288

253-
json eventArray;
289+
json eventArray = json::array();
254290
eventArray.push_back(jsonObject);
255291

256292
std::string payloadJSONString = eventArray.dump();
@@ -297,6 +333,12 @@ namespace gameanalytics
297333
std::string auth = createAuth(payloadData);
298334
GAHttpWrapper::Response response = impl->sendRequest(url, auth, payloadData, useGzip, nullptr);
299335

336+
if(response.code < 0)
337+
{
338+
logging::GALogger::e("Request failed: %s", url.c_str());
339+
return;
340+
}
341+
300342
std::string_view content = response.toString();
301343

302344
// process the response

0 commit comments

Comments
 (0)