in client-library/src/Attestation/AttestationClient/lib/AttestationLibUtils.cpp [230:279]
static std::string getErrorMessage(const std::string& http_response) {
std::string error_str;
Json::Value response;
Json::Reader reader;
bool success = reader.parse(http_response.c_str(), response);
if(!success) {
CLIENT_LOG_ERROR("Failed to parse http response");
return error_str;
}
// In case of server errors, the json keys are Camel cases and keys
// are lower case for all other errors.
Json::Value error_obj;
if(response.isMember(JSON_HTTP_ERROR_KEY)) {
error_obj = response.get(JSON_HTTP_ERROR_KEY, Json::Value());
} else {
error_obj = response.get(JSON_HTTP_ERROR_LOWER_KEY, Json::Value());
}
if(error_obj.isNull()) {
CLIENT_LOG_ERROR("Failed to find error obj in http response");
return error_str;
}
std::string error_code;
if(error_obj.isMember(JSON_HTTP_ERROR_CODE_KEY)) {
error_code = error_obj.get(JSON_HTTP_ERROR_CODE_KEY, "").asString();
} else {
error_code = error_obj.get(JSON_HTTP_ERROR_CODE_LOWER_KEY, "").asString();
}
if(error_code.empty()) {
CLIENT_LOG_ERROR("Failed to get error code from http response");
return error_str;
}
std::string error_message;
if(error_obj.isMember(JSON_HTTP_ERROR_MESSAGE_KEY)) {
error_message = error_obj.get(JSON_HTTP_ERROR_MESSAGE_KEY, "").asString();
} else {
error_message = error_obj.get(JSON_HTTP_ERROR_MESSAGE_LOWER_KEY, "").asString();
}
if(error_message.empty()) {
CLIENT_LOG_ERROR("Failed to get error message from http response");
return error_str;
}
// The error str being returned contains both the error code and the
// error message in the format code:message.
error_str = error_code + ":" + error_message;
return error_str;
}