summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mbgl/util/exception.hpp5
-rw-r--r--src/mbgl/map/resource_loader.cpp4
-rw-r--r--src/mbgl/map/resource_loader.hpp1
-rw-r--r--src/mbgl/map/source.cpp18
-rw-r--r--src/mbgl/map/source.hpp3
5 files changed, 29 insertions, 2 deletions
diff --git a/include/mbgl/util/exception.hpp b/include/mbgl/util/exception.hpp
index 0b4403270c..050e56da38 100644
--- a/include/mbgl/util/exception.hpp
+++ b/include/mbgl/util/exception.hpp
@@ -21,6 +21,11 @@ struct ShaderException : Exception {
inline ShaderException(const std::string &msg) : Exception(msg) {}
};
+struct SourceLoadingException : Exception {
+ inline SourceLoadingException(const char *msg) : Exception(msg) {}
+ inline SourceLoadingException(const std::string &msg) : Exception(msg) {}
+};
+
}
}
diff --git a/src/mbgl/map/resource_loader.cpp b/src/mbgl/map/resource_loader.cpp
index 620b1b1379..a7dbc67d84 100644
--- a/src/mbgl/map/resource_loader.cpp
+++ b/src/mbgl/map/resource_loader.cpp
@@ -108,6 +108,10 @@ void ResourceLoader::onSourceLoaded() {
emitTileDataChanged();
}
+void ResourceLoader::onSourceLoadingFailed(std::exception_ptr error) {
+ emitResourceLoadingFailed(error);
+}
+
void ResourceLoader::onTileLoaded(bool isNewTile) {
if (isNewTile) {
shouldReparsePartialTiles_ = true;
diff --git a/src/mbgl/map/resource_loader.hpp b/src/mbgl/map/resource_loader.hpp
index fb05e67e1d..70b79d8fe4 100644
--- a/src/mbgl/map/resource_loader.hpp
+++ b/src/mbgl/map/resource_loader.hpp
@@ -66,6 +66,7 @@ public:
// Source::Observer implementation.
void onSourceLoaded() override;
+ void onSourceLoadingFailed(std::exception_ptr error) override;
void onTileLoaded(bool isNewTile) override;
// Sprite::Observer implementation.
diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp
index e8dc3468d3..37bc40830b 100644
--- a/src/mbgl/map/source.cpp
+++ b/src/mbgl/map/source.cpp
@@ -4,6 +4,7 @@
#include <mbgl/map/transform.hpp>
#include <mbgl/map/tile.hpp>
#include <mbgl/renderer/painter.hpp>
+#include <mbgl/util/exception.hpp>
#include <mbgl/util/constants.hpp>
#include <mbgl/storage/resource.hpp>
#include <mbgl/storage/response.hpp>
@@ -150,7 +151,9 @@ void Source::load(const std::string& accessToken) {
req = nullptr;
if (res.status != Response::Successful) {
- Log::Warning(Event::General, "Failed to load source TileJSON: %s", res.message.c_str());
+ std::stringstream message;
+ message << "Failed to load [" << info.url << "]: " << res.message;
+ emitSourceLoadingFailed(message.str());
return;
}
@@ -158,7 +161,9 @@ void Source::load(const std::string& accessToken) {
d.Parse<0>(res.data.c_str());
if (d.HasParseError()) {
- Log::Error(Event::General, "Invalid source TileJSON; Parse Error at %d: %s", d.GetErrorOffset(), d.GetParseError());
+ std::stringstream message;
+ message << "Failed to parse [" << info.url << "]: " << d.GetErrorOffset() << " - " << d.GetParseError();
+ emitSourceLoadingFailed(message.str());
return;
}
@@ -536,6 +541,15 @@ void Source::emitSourceLoaded() {
}
}
+void Source::emitSourceLoadingFailed(const std::string& message) {
+ if (!observer_) {
+ return;
+ }
+
+ auto error = std::make_exception_ptr(util::SourceLoadingException(message));
+ observer_->onSourceLoadingFailed(error);
+}
+
void Source::emitTileLoaded(bool isNewTile) {
if (observer_) {
observer_->onTileLoaded(isNewTile);
diff --git a/src/mbgl/map/source.hpp b/src/mbgl/map/source.hpp
index 9d3de81b70..781e8621a7 100644
--- a/src/mbgl/map/source.hpp
+++ b/src/mbgl/map/source.hpp
@@ -58,6 +58,8 @@ public:
virtual ~Observer() = default;
virtual void onSourceLoaded() = 0;
+ virtual void onSourceLoadingFailed(std::exception_ptr error) = 0;
+
virtual void onTileLoaded(bool isNewTile) = 0;
};
@@ -102,6 +104,7 @@ public:
private:
void emitSourceLoaded();
+ void emitSourceLoadingFailed(const std::string& message);
void emitTileLoaded(bool isNewTile);
bool handlePartialTile(const TileID &id, Worker &worker);