Notify failures when loading the source JSON
This commit is contained in:
@@ -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) {}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user