Commit 0deb9dde authored by Beat Küng's avatar Beat Küng

AirMapManager: error handling, change to updated API of airmapd

parent 22169ffe
...@@ -67,12 +67,9 @@ void AirMapSharedState::login() ...@@ -67,12 +67,9 @@ void AirMapSharedState::login()
_processPendingRequests(); _processPendingRequests();
} else { } else {
_pendingRequests.clear(); _pendingRequests.clear();
try { QString description = QString::fromStdString(result.error().description() ? result.error().description().get() : "");
std::rethrow_exception(result.error()); emit error("Failed to authenticate with AirMap",
} catch (const std::exception& e) { QString::fromStdString(result.error().message()), description);
// TODO: emit signal
emit error("Failed to authenticate with AirMap", e.what(), "");
}
} }
}); });
...@@ -95,12 +92,9 @@ void AirMapSharedState::login() ...@@ -95,12 +92,9 @@ void AirMapSharedState::login()
_processPendingRequests(); _processPendingRequests();
} else { } else {
_pendingRequests.clear(); _pendingRequests.clear();
try { QString description = QString::fromStdString(result.error().description() ? result.error().description().get() : "");
std::rethrow_exception(result.error()); emit error("Failed to authenticate with AirMap",
} catch (const std::exception& e) { QString::fromStdString(result.error().message()), description);
// TODO: proper error handling
emit error("Failed to authenticate with AirMap", e.what(), "");
}
} }
}); });
} }
...@@ -129,8 +123,6 @@ void AirMapSharedState::logout() ...@@ -129,8 +123,6 @@ void AirMapSharedState::logout()
AirMapRestrictionManager::AirMapRestrictionManager(AirMapSharedState& shared) AirMapRestrictionManager::AirMapRestrictionManager(AirMapSharedState& shared)
: _shared(shared) : _shared(shared)
{ {
//connect(&_networking, &AirMapNetworking::finished, this, &AirMapRestrictionManager::_parseAirspaceJson);
//connect(&_networking, &AirMapNetworking::error, this, &AirMapRestrictionManager::_error);
} }
void AirMapRestrictionManager::setROI(const QGeoCoordinate& center, double radiusMeters) void AirMapRestrictionManager::setROI(const QGeoCoordinate& center, double radiusMeters)
...@@ -195,12 +187,9 @@ void AirMapRestrictionManager::setROI(const QGeoCoordinate& center, double radiu ...@@ -195,12 +187,9 @@ void AirMapRestrictionManager::setROI(const QGeoCoordinate& center, double radiu
} }
} else { } else {
try { QString description = QString::fromStdString(result.error().description() ? result.error().description().get() : "");
std::rethrow_exception(result.error()); emit error("Failed to authenticate with AirMap",
} catch (const std::exception& e) { QString::fromStdString(result.error().message()), description);
// TODO: proper error handling
emit error("Failed to authenticate with AirMap", e.what(), "");
}
} }
emit requestDone(true); emit requestDone(true);
_state = State::Idle; _state = State::Idle;
...@@ -303,12 +292,9 @@ void AirMapFlightManager::createFlight(const QList<MissionItem*>& missionItems) ...@@ -303,12 +292,9 @@ void AirMapFlightManager::createFlight(const QList<MissionItem*>& missionItems)
emit flightPermitStatusChanged(); emit flightPermitStatusChanged();
_state = State::Idle; _state = State::Idle;
try { QString description = QString::fromStdString(result.error().description() ? result.error().description().get() : "");
std::rethrow_exception(result.error()); emit error("Failed to create Flight Plan",
} catch (const std::exception& e) { QString::fromStdString(result.error().message()), description);
// TODO: proper error handling
emit error("Failed to create Flight Plan", e.what(), "");
}
} }
}); });
}); });
...@@ -348,12 +334,9 @@ void AirMapFlightManager::_endFirstFlight() ...@@ -348,12 +334,9 @@ void AirMapFlightManager::_endFirstFlight()
if (_state != State::EndFirstFlight) return; if (_state != State::EndFirstFlight) return;
if (!result) { if (!result) {
try { QString description = QString::fromStdString(result.error().description() ? result.error().description().get() : "");
std::rethrow_exception(result.error()); emit error("Failed to end first Flight",
} catch (const std::exception& e) { QString::fromStdString(result.error().message()), description);
// TODO: emit signal
emit error("Failed to end first Flight", e.what(), "");
}
} }
_state = State::Idle; _state = State::Idle;
_uploadFlight(); _uploadFlight();
...@@ -428,8 +411,9 @@ void AirMapFlightManager::_uploadFlight() ...@@ -428,8 +411,9 @@ void AirMapFlightManager::_uploadFlight()
_checkForValidBriefing(); _checkForValidBriefing();
} else { } else {
// TODO QString description = QString::fromStdString(result.error().description() ? result.error().description().get() : "");
qCDebug(AirMapManagerLog) << "Flight Plan creation failed"; emit error("Flight Plan creation failed",
QString::fromStdString(result.error().message()), description);
} }
}); });
...@@ -466,7 +450,10 @@ void AirMapFlightManager::_checkForValidBriefing() ...@@ -466,7 +450,10 @@ void AirMapFlightManager::_checkForValidBriefing()
} }
} else { } else {
// TODO QString description = QString::fromStdString(result.error().description() ? result.error().description().get() : "");
emit error("Brief Request failed",
QString::fromStdString(result.error().message()), description);
_state = State::Idle;
} }
}); });
} }
...@@ -488,7 +475,10 @@ void AirMapFlightManager::_submitPendingFlightPlan() ...@@ -488,7 +475,10 @@ void AirMapFlightManager::_submitPendingFlightPlan()
_pollBriefing(); _pollBriefing();
} else { } else {
// TODO QString description = QString::fromStdString(result.error().description() ? result.error().description().get() : "");
emit error("Failed to submit Flight Plan",
QString::fromStdString(result.error().message()), description);
_state = State::Idle;
} }
}); });
} }
...@@ -553,7 +543,10 @@ void AirMapFlightManager::_pollBriefing() ...@@ -553,7 +543,10 @@ void AirMapFlightManager::_pollBriefing()
_pollTimer.start(2000); _pollTimer.start(2000);
} }
} else { } else {
// TODO: error handling QString description = QString::fromStdString(result.error().description() ? result.error().description().get() : "");
emit error("Brief Request failed",
QString::fromStdString(result.error().message()), description);
_state = State::Idle;
} }
}); });
} }
...@@ -598,12 +591,9 @@ void AirMapFlightManager::_endFlight(const QString& flightID) ...@@ -598,12 +591,9 @@ void AirMapFlightManager::_endFlight(const QString& flightID)
_uploadFlight(); _uploadFlight();
} }
} else { } else {
try { QString description = QString::fromStdString(result.error().description() ? result.error().description().get() : "");
std::rethrow_exception(result.error()); emit error("Failed to end Flight",
} catch (const std::exception& e) { QString::fromStdString(result.error().message()), description);
// TODO: emit signal
emit error("Failed to end Flight", e.what(), "");
}
} }
}); });
} }
...@@ -704,12 +694,9 @@ void AirMapTelemetry::startTelemetryStream(const QString& flightID) ...@@ -704,12 +694,9 @@ void AirMapTelemetry::startTelemetryStream(const QString& flightID)
_state = State::Streaming; _state = State::Streaming;
} else { } else {
_state = State::Idle; _state = State::Idle;
try { QString description = QString::fromStdString(result.error().description() ? result.error().description().get() : "");
std::rethrow_exception(result.error()); emit error("Failed to start telemetry streaming",
} catch (const std::exception& e) { QString::fromStdString(result.error().message()), description);
// TODO: emit signal
emit error("Failed to start telemetry streaming", e.what(), "");
}
} }
}); });
} }
...@@ -753,11 +740,9 @@ void AirMapTrafficMonitor::startConnection(const QString& flightID) ...@@ -753,11 +740,9 @@ void AirMapTrafficMonitor::startConnection(const QString& flightID)
std::bind(&AirMapTrafficMonitor::_update, this, std::placeholders::_1, std::placeholders::_2)); std::bind(&AirMapTrafficMonitor::_update, this, std::placeholders::_1, std::placeholders::_2));
_monitor->subscribe(_subscriber); _monitor->subscribe(_subscriber);
} else { } else {
try { QString description = QString::fromStdString(result.error().description() ? result.error().description().get() : "");
std::rethrow_exception(result.error()); emit error("Failed to start Traffic Monitoring",
} catch (const std::exception& e) { QString::fromStdString(result.error().message()), description);
// TODO: error
}
} }
}; };
...@@ -799,8 +784,9 @@ AirMapManagerPerVehicle::AirMapManagerPerVehicle(AirMapSharedState& shared, cons ...@@ -799,8 +784,9 @@ AirMapManagerPerVehicle::AirMapManagerPerVehicle(AirMapSharedState& shared, cons
this, &AirMapManagerPerVehicle::flightPermitStatusChanged); this, &AirMapManagerPerVehicle::flightPermitStatusChanged);
connect(&_flightManager, &AirMapFlightManager::flightPermitStatusChanged, connect(&_flightManager, &AirMapFlightManager::flightPermitStatusChanged,
this, &AirMapManagerPerVehicle::_flightPermitStatusChanged); this, &AirMapManagerPerVehicle::_flightPermitStatusChanged);
//connect(&_flightManager, &AirMapFlightManager::networkError, this, &AirMapManagerPerVehicle::networkError); connect(&_flightManager, &AirMapFlightManager::error, this, &AirMapManagerPerVehicle::error);
//connect(&_telemetry, &AirMapTelemetry::networkError, this, &AirMapManagerPerVehicle::networkError); connect(&_telemetry, &AirMapTelemetry::error, this, &AirMapManagerPerVehicle::error);
connect(&_trafficMonitor, &AirMapTrafficMonitor::error, this, &AirMapManagerPerVehicle::error);
connect(&_trafficMonitor, &AirMapTrafficMonitor::trafficUpdate, this, &AirspaceManagerPerVehicle::trafficUpdate); connect(&_trafficMonitor, &AirMapTrafficMonitor::trafficUpdate, this, &AirspaceManagerPerVehicle::trafficUpdate);
} }
...@@ -894,9 +880,8 @@ void AirMapManager::setToolbox(QGCToolbox* toolbox) ...@@ -894,9 +880,8 @@ void AirMapManager::setToolbox(QGCToolbox* toolbox)
void AirMapManager::_error(const QString& what, const QString& airmapdMessage, const QString& airmapdDetails) void AirMapManager::_error(const QString& what, const QString& airmapdMessage, const QString& airmapdDetails)
{ {
//TODO: console message & UI message qCDebug(AirMapManagerLog) << "Error: "<<what<<", msg: "<<airmapdMessage<<", details: "<<airmapdDetails;
//qgcApp()->showMessage(QString("AirMap error: %1%2").arg(errorString).arg(errorDetails)); qgcApp()->showMessage(QString("AirMap Error: %1. %2").arg(what).arg(airmapdMessage));
qCDebug(AirMapManagerLog) << "Caught error: "<<what<<", "<<airmapdMessage<<", "<<airmapdDetails;
} }
void AirMapManager::requestWeatherUpdate(const QGeoCoordinate& coordinate) void AirMapManager::requestWeatherUpdate(const QGeoCoordinate& coordinate)
...@@ -931,7 +916,6 @@ void AirMapManager::requestWeatherUpdate(const QGeoCoordinate& coordinate) ...@@ -931,7 +916,6 @@ void AirMapManager::requestWeatherUpdate(const QGeoCoordinate& coordinate)
emit weatherUpdate(true, coordinate, weatherUpdateInfo); emit weatherUpdate(true, coordinate, weatherUpdateInfo);
} else { } else {
// TODO: error handling
emit weatherUpdate(false, coordinate, WeatherInformation{}); emit weatherUpdate(false, coordinate, WeatherInformation{});
} }
}); });
...@@ -972,7 +956,9 @@ void AirMapManager::_settingsChanged() ...@@ -972,7 +956,9 @@ void AirMapManager::_settingsChanged()
} else { } else {
qWarning("Failed to create airmap::qt::Client instance"); qWarning("Failed to create airmap::qt::Client instance");
// TODO: user error message QString description = QString::fromStdString(result.error().description() ? result.error().description().get() : "");
_error("Failed to create airmap::qt::Client instance",
QString::fromStdString(result.error().message()), description);
} }
}); });
} }
...@@ -981,14 +967,13 @@ void AirMapManager::_settingsChanged() ...@@ -981,14 +967,13 @@ void AirMapManager::_settingsChanged()
AirspaceManagerPerVehicle* AirMapManager::instantiateVehicle(const Vehicle& vehicle) AirspaceManagerPerVehicle* AirMapManager::instantiateVehicle(const Vehicle& vehicle)
{ {
AirMapManagerPerVehicle* manager = new AirMapManagerPerVehicle(_shared, vehicle, *_toolbox); AirMapManagerPerVehicle* manager = new AirMapManagerPerVehicle(_shared, vehicle, *_toolbox);
//connect(manager, &AirMapManagerPerVehicle::networkError, this, &AirMapManager::_networkError); connect(manager, &AirMapManagerPerVehicle::error, this, &AirMapManager::_error);
return manager; return manager;
} }
AirspaceRestrictionProvider* AirMapManager::instantiateRestrictionProvider() AirspaceRestrictionProvider* AirMapManager::instantiateRestrictionProvider()
{ {
AirMapRestrictionManager* restrictionManager = new AirMapRestrictionManager(_shared); AirMapRestrictionManager* restrictionManager = new AirMapRestrictionManager(_shared);
//connect(restrictionManager, &AirMapRestrictionManager::networkError, this, &AirMapManager::_networkError);
connect(restrictionManager, &AirMapRestrictionManager::error, this, &AirMapManager::_error); connect(restrictionManager, &AirMapRestrictionManager::error, this, &AirMapManager::_error);
return restrictionManager; return restrictionManager;
} }
......
...@@ -279,6 +279,7 @@ public: ...@@ -279,6 +279,7 @@ public:
void stop(); void stop();
signals: signals:
void error(const QString& what, const QString& airmapdMessage, const QString& airmapdDetails);
void trafficUpdate(QString traffic_id, QString vehicle_id, QGeoCoordinate location, float heading); void trafficUpdate(QString traffic_id, QString vehicle_id, QGeoCoordinate location, float heading);
private: private:
...@@ -313,7 +314,7 @@ public: ...@@ -313,7 +314,7 @@ public:
bool isTelemetryStreaming() const override; bool isTelemetryStreaming() const override;
signals: signals:
void networkError(QNetworkReply::NetworkError code, const QString& errorString, const QString& serverErrorMessage); void error(const QString& what, const QString& airmapdMessage, const QString& airmapdDetails);
public slots: public slots:
void endFlight() override; void endFlight() override;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment