ORE Studio 0.0.4
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
exception_helper Class Referencefinal

Helper class for handling exceptions and server errors in async operations. More...

#include <ExceptionHelper.hpp>

Collaboration diagram for exception_helper:
Collaboration graph

Static Public Member Functions

static std::optional< server_error_infocheck_error_response (const comms::messaging::frame &response)
 Check if a response frame is an error_response and extract the message.
 
template<typename Logger , typename EmitFunc >
static void handle_fetch_exception (const std::exception &e, const QString &entity_name, Logger &logger, EmitFunc emit_error)
 Handles a fetch exception by logging and emitting an error signal.
 
template<typename ResultType , typename FetchFunc >
static ResultType wrap_async_fetch (FetchFunc &&fetch_func, const QString &entity_name)
 Wraps an async fetch operation to capture exceptions before Qt can wrap them.
 

Detailed Description

Helper class for handling exceptions and server errors in async operations.

Provides standardized handling for:

Member Function Documentation

◆ check_error_response()

static std::optional< server_error_info > check_error_response ( const comms::messaging::frame response)
static

Check if a response frame is an error_response and extract the message.

Call this after receiving a response but before attempting to deserialize as the expected response type. If the server sent an error_response, this extracts the human-readable error message.

Parameters
responseThe response frame from sendRequest().
Returns
The error info if this is an error_response, nullopt otherwise.

◆ handle_fetch_exception()

template<typename Logger , typename EmitFunc >
static void handle_fetch_exception ( const std::exception &  e,
const QString &  entity_name,
Logger &  logger,
EmitFunc  emit_error 
)
static

Handles a fetch exception by logging and emitting an error signal.

Extracts detailed diagnostic information from the exception using boost::diagnostic_information, logs the error, and calls the emit callback with a user-friendly message and technical details.

Template Parameters
LoggerThe logger type (must support BOOST_LOG_SEV).
EmitFuncCallable that takes (const QString& message, const QString& details).
Parameters
eThe exception that was caught.
entity_nameThe name of the entity being fetched (e.g., "origin dimensions").
loggerReference to the logger instance.
emit_errorCallback to emit the error signal.

◆ wrap_async_fetch()

template<typename ResultType , typename FetchFunc >
static ResultType wrap_async_fetch ( FetchFunc &&  fetch_func,
const QString &  entity_name 
)
static

Wraps an async fetch operation to capture exceptions before Qt can wrap them.

This function catches exceptions inside the async task (before Qt's exception handling), capturing full diagnostic information. The result type must have the following fields:

  • bool success
  • QString error_message
  • QString error_details
Template Parameters
ResultTypeThe FetchResult type (must have success, error_message, error_details).
FetchFuncCallable that returns ResultType.
Parameters
fetch_funcThe function that performs the actual fetch.
entity_nameThe name of the entity being fetched (for error messages).
Returns
ResultType with success=false and error fields populated on exception.