Audacity 3.2.0
Public Member Functions | Private Attributes | List of all members
audacity::sentry::Report::ReportImpl Class Reference

Public Member Functions

 ReportImpl (const Exception &exception)
 
 ReportImpl (const Message &message)
 
void AddUserComment (const std::string &message)
 
std::string ToString (bool pretty) const
 
void Send (CompletionHandler completionHandler) const
 

Private Attributes

rapidjson::Document mDocument
 

Detailed Description

Definition at line 261 of file SentryReport.cpp.

Constructor & Destructor Documentation

◆ ReportImpl() [1/2]

audacity::sentry::Report::ReportImpl::ReportImpl ( const Exception exception)
explicit

Definition at line 278 of file SentryReport.cpp.

280{
281 rapidjson::Value exceptionObject(rapidjson::kObjectType);
282 rapidjson::Value valuesArray(rapidjson::kArrayType);
283 rapidjson::Value valueObject(rapidjson::kObjectType);
284
285 SerializeException(exception, valueObject, mDocument.GetAllocator());
286
287 valuesArray.PushBack(std::move(valueObject), mDocument.GetAllocator());
288
289 exceptionObject.AddMember(
290 "values", std::move(valuesArray), mDocument.GetAllocator());
291
292 mDocument.AddMember(
293 "exception", std::move(exceptionObject), mDocument.GetAllocator());
294}
rapidjson::Document CreateSentryDocument()
Create the minimal required Sentry JSON document.
void SerializeException(const Exception &exception, rapidjson::Value &root, rapidjson::Document::AllocatorType &allocator)
Serialize the Exception to JSON.

References mDocument, and audacity::sentry::anonymous_namespace{SentryReport.cpp}::SerializeException().

Here is the call graph for this function:

◆ ReportImpl() [2/2]

audacity::sentry::Report::ReportImpl::ReportImpl ( const Message message)
explicit

Definition at line 296 of file SentryReport.cpp.

298{
299 rapidjson::Value messageObject(rapidjson::kObjectType);
300
301 messageObject.AddMember(
302 "message",
303 rapidjson::Value(
304 message.Value.c_str(), message.Value.length(),
305 mDocument.GetAllocator()),
306 mDocument.GetAllocator());
307
308 if (!message.Params.empty())
309 {
310 rapidjson::Value paramsArray(rapidjson::kArrayType);
311
312 for (const AnonymizedMessage& param : message.Params)
313 {
314 paramsArray.PushBack(
315 rapidjson::Value(
316 param.c_str(), param.length(), mDocument.GetAllocator()),
317 mDocument.GetAllocator());
318 }
319
320 messageObject.AddMember(
321 "params", std::move(paramsArray), mDocument.GetAllocator());
322 }
323
324 mDocument.AddMember(
325 "message", std::move(messageObject), mDocument.GetAllocator());
326}

References audacity::sentry::AnonymizedMessage::c_str(), audacity::sentry::AnonymizedMessage::length(), mDocument, audacity::sentry::Message::Params, and audacity::sentry::Message::Value.

Here is the call graph for this function:

Member Function Documentation

◆ AddUserComment()

void audacity::sentry::Report::ReportImpl::AddUserComment ( const std::string &  message)

Definition at line 328 of file SentryReport.cpp.

329{
330 // We only allow adding comment to exceptions now
331 if (!mDocument.HasMember("exception") || message.empty())
332 return;
333
334 rapidjson::Value& topException = mDocument["exception"]["values"][0];
335
336 if (!topException.IsObject())
337 return;
338
339 rapidjson::Value& mechanism = topException["mechanism"];
340
341 // Create a data object if it still does not exist
342 if (!mechanism.HasMember("data"))
343 {
344 mechanism.AddMember(
345 "data", rapidjson::Value(rapidjson::kObjectType),
346 mDocument.GetAllocator());
347 }
348
349 // Add a comment itself
350 mechanism["data"].AddMember(
351 "user_comment",
352 rapidjson::Value(
353 message.data(), message.length(), mDocument.GetAllocator()),
354 mDocument.GetAllocator());
355}

◆ Send()

void audacity::sentry::Report::ReportImpl::Send ( CompletionHandler  completionHandler) const

Definition at line 358 of file SentryReport.cpp.

359{
360 const std::string serializedDocument = ToString(false);
361
362 network_manager::Request request =
364
366 request, serializedDocument.data(), serializedDocument.size());
367
368 response->setRequestFinishedCallback(
369 [response, handler = std::move(completionHandler)](network_manager::IResponse*) {
370 const std::string responseData = response->readAll<std::string>();
371
372 wxLogDebug(responseData.c_str());
373
374 if (handler)
375 handler(response->getHTTPCode(), responseData);
376 });
377}
ResponsePtr doPost(const Request &request, const void *data, size_t size)
std::string ToString(bool pretty) const
static const SentryRequestBuilder & Get()
network_manager::Request CreateRequest() const

References audacity::sentry::SentryRequestBuilder::CreateRequest(), audacity::network_manager::NetworkManager::doPost(), audacity::sentry::SentryRequestBuilder::Get(), audacity::network_manager::NetworkManager::GetInstance(), audacity::cloud::audiocom::anonymous_namespace{AuthorizationHandler.cpp}::handler, and MIR::ToString().

Here is the call graph for this function:

◆ ToString()

std::string audacity::sentry::Report::ReportImpl::ToString ( bool  pretty) const

Definition at line 379 of file SentryReport.cpp.

380{
381 rapidjson::StringBuffer buffer;
382
383 if (pretty)
384 {
385 rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
386 mDocument.Accept(writer);
387 }
388 else
389 {
390 rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
391 mDocument.Accept(writer);
392 }
393
394 return std::string(buffer.GetString());
395}

Member Data Documentation

◆ mDocument

rapidjson::Document audacity::sentry::Report::ReportImpl::mDocument
private

Definition at line 274 of file SentryReport.cpp.

Referenced by ReportImpl().


The documentation for this class was generated from the following file: