20#ifndef ORES_QT_EXCEPTION_HELPER_HPP
21#define ORES_QT_EXCEPTION_HELPER_HPP
26#include <boost/exception/diagnostic_information.hpp>
27#include "ores.logging/boost_severity.hpp"
28#include "ores.comms/messaging/frame.hpp"
29#include "ores.comms/messaging/error_protocol.hpp"
60 static std::optional<server_error_info>
62 using comms::messaging::message_type;
65 if (response.
header().type != message_type::error_response) {
70 if (!payload_result) {
72 .message =
"Server returned an error (failed to decompress)",
77 auto err_resp = error_response::deserialize(*payload_result);
80 .message =
"Server returned an error (failed to parse)",
86 .message = QString(
"Server error: %1")
87 .arg(QString::fromStdString(err_resp->message)),
88 .details = QString(
"Error code: %1 (%2)")
89 .arg(QString::fromStdString(
90 ores::utility::serialization::to_string(err_resp->code)))
91 .arg(
static_cast<int>(err_resp->code))
109 template<
typename Logger,
typename EmitFunc>
111 const std::exception& e,
112 const QString& entity_name,
114 EmitFunc emit_error) {
116 const auto details = QString::fromStdString(
117 boost::diagnostic_information(e));
119 BOOST_LOG_SEV(logger, ores::logging::error)
120 <<
"Exception fetching " << entity_name.toStdString() <<
": "
121 << details.toStdString();
123 const auto message = QString(
"Failed to fetch %1 from server.")
126 emit_error(message, details);
145 template<
typename ResultType,
typename FetchFunc>
147 FetchFunc&& fetch_func,
148 const QString& entity_name) {
152 }
catch (
const std::exception& e) {
154 result.success =
false;
155 result.error_message = QString(
"Failed to fetch %1 from server.")
157 result.error_details = QString::fromStdString(
158 boost::diagnostic_information(e));
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:35
Error response message sent when request processing fails.
Definition error_protocol.hpp:34
Complete frame with header and payload.
Definition frame.hpp:77
const frame_header & header() const
Get the frame header.
Definition frame.hpp:103
std::expected< std::vector< std::byte >, ores::utility::serialization::error_code > decompressed_payload() const
Decompress and return the payload.
Definition frame.cpp:361
Result of checking a response frame for server errors.
Definition ExceptionHelper.hpp:36
Helper class for handling exceptions and server errors in async operations.
Definition ExceptionHelper.hpp:48
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.
Definition ExceptionHelper.hpp:61
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.
Definition ExceptionHelper.hpp:146
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.
Definition ExceptionHelper.hpp:110