| 49 | const std::string ITWIN_TOKEN_URL = "https://ims.bentley.com/connect/token"; |
| 50 | |
| 51 | Result<rapidjson::Document> handleJsonResponse( |
| 52 | std::shared_ptr<CesiumAsync::IAssetRequest>& pRequest, |
| 53 | const std::string& operation) { |
| 54 | const CesiumAsync::IAssetResponse* pResponse = pRequest->response(); |
| 55 | if (!pResponse) { |
| 56 | return Result<rapidjson::Document>( |
| 57 | ErrorList::error("The server did not return a response.")); |
| 58 | } |
| 59 | |
| 60 | if (pResponse->statusCode() < 200 || pResponse->statusCode() >= 300) { |
| 61 | std::string error, errorDesc; |
| 62 | if (CesiumClientCommon::parseErrorResponse( |
| 63 | pResponse->data(), |
| 64 | error, |
| 65 | errorDesc)) { |
| 66 | return Result<rapidjson::Document>(ErrorList::error(fmt::format( |
| 67 | "Received error '{}' while {}: {}", |
| 68 | error, |
| 69 | operation, |
| 70 | errorDesc))); |
| 71 | } |
| 72 | |
| 73 | return Result<rapidjson::Document>(ErrorList::error(fmt::format( |
| 74 | "The server returned an error code: {}", |
| 75 | pResponse->statusCode()))); |
| 76 | } |
| 77 | |
| 78 | rapidjson::Document d; |
| 79 | d.Parse( |
| 80 | reinterpret_cast<const char*>(pResponse->data().data()), |
| 81 | pResponse->data().size()); |
| 82 | if (d.HasParseError()) { |
| 83 | return Result<rapidjson::Document>(ErrorList::error(fmt::format( |
| 84 | "Failed to parse JSON response: {}", |
| 85 | rapidjson::GetParseError_En(d.GetParseError())))); |
| 86 | } else if (!d.IsObject()) { |
| 87 | return Result<rapidjson::Document>( |
| 88 | ErrorList::error("No JSON object contained in response.")); |
| 89 | } |
| 90 | |
| 91 | return Result<rapidjson::Document>(std::move(d)); |
| 92 | } |
| 93 | |
| 94 | CesiumGeospatial::Cartographic parsePoint(const rapidjson::Value& jsonValue) { |
| 95 | double latitudeDegrees = 0, longitudeDegrees = 0; |
no test coverage detected