Helper class for handling exceptions and server errors in async operations.
More...
#include <ExceptionHelper.hpp>
|
| static std::optional< server_error_info > | check_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.
|
| |
Helper class for handling exceptions and server errors in async operations.
Provides standardized handling for:
- Exceptions thrown from QFuture operations
- Server error responses (message_type::error_response)
◆ check_error_response()
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
-
| response | The 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
-
| Logger | The logger type (must support BOOST_LOG_SEV). |
| EmitFunc | Callable that takes (const QString& message, const QString& details). |
- Parameters
-
| e | The exception that was caught. |
| entity_name | The name of the entity being fetched (e.g., "origin dimensions"). |
| logger | Reference to the logger instance. |
| emit_error | Callback 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
-
| ResultType | The FetchResult type (must have success, error_message, error_details). |
| FetchFunc | Callable that returns ResultType. |
- Parameters
-
| fetch_func | The function that performs the actual fetch. |
| entity_name | The name of the entity being fetched (for error messages). |
- Returns
- ResultType with success=false and error fields populated on exception.