| 111 | } |
| 112 | |
| 113 | size_t PlayFabHttp::CurlReceiveData(char* buffer, size_t blockSize, size_t blockCount, void* userData) |
| 114 | { |
| 115 | CallRequestContainer* reqContainer = reinterpret_cast<CallRequestContainer*>(userData); |
| 116 | reqContainer->responseString.assign(buffer, blockSize * blockCount); |
| 117 | |
| 118 | Json::CharReaderBuilder jsonReaderFactory; |
| 119 | Json::CharReader* jsonReader(jsonReaderFactory.newCharReader()); |
| 120 | JSONCPP_STRING jsonParseErrors; |
| 121 | const bool parsedSuccessfully = jsonReader->parse(reqContainer->responseString.c_str(), reqContainer->responseString.c_str() + reqContainer->responseString.length(), &reqContainer->responseJson, &jsonParseErrors); |
| 122 | |
| 123 | if (parsedSuccessfully) |
| 124 | { |
| 125 | reqContainer->errorWrapper.HttpCode = reqContainer->responseJson.get("code", Json::Value::null).asInt(); |
| 126 | reqContainer->errorWrapper.HttpStatus = reqContainer->responseJson.get("status", Json::Value::null).asString(); |
| 127 | reqContainer->errorWrapper.Data = reqContainer->responseJson.get("data", Json::Value::null); |
| 128 | reqContainer->errorWrapper.ErrorName = reqContainer->responseJson.get("error", Json::Value::null).asString(); |
| 129 | reqContainer->errorWrapper.ErrorMessage = reqContainer->responseJson.get("errorMessage", Json::Value::null).asString(); |
| 130 | reqContainer->errorWrapper.ErrorDetails = reqContainer->responseJson.get("errorDetails", Json::Value::null); |
| 131 | } |
| 132 | else |
| 133 | { |
| 134 | reqContainer->errorWrapper.HttpCode = 408; |
| 135 | reqContainer->errorWrapper.HttpStatus = reqContainer->responseString; |
| 136 | reqContainer->errorWrapper.ErrorCode = PlayFabErrorConnectionTimeout; |
| 137 | reqContainer->errorWrapper.ErrorName = "Failed to parse PlayFab response"; |
| 138 | reqContainer->errorWrapper.ErrorMessage = jsonParseErrors; |
| 139 | } |
| 140 | |
| 141 | HandleCallback(*reqContainer); |
| 142 | return (blockSize * blockCount); |
| 143 | } |
| 144 | |
| 145 | void PlayFabHttp::AddRequest(const std::string& urlPath, const std::string& authKey, const std::string& authValue, const Json::Value& requestBody, RequestCompleteCallback internalCallback, SharedVoidPointer successCallback, ErrorCallback errorCallback, void* customData) |
| 146 | { |