diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2017-07-27 15:27:59 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2017-07-27 15:27:59 +0200 |
commit | efbdf40b0251f09556ce65c0378474c67696ba37 (patch) | |
tree | 16278f14423d278aabfe9b433e869a1e4b8af177 | |
parent | d7b7b01d7edcdcfd4c5c542614391081911ab8ed (diff) | |
download | qtlocation-mapboxgl-efbdf40b0251f09556ce65c0378474c67696ba37.tar.gz |
fixup resource
-rw-r--r-- | include/mbgl/storage/resource_error.hpp | 33 | ||||
-rw-r--r-- | platform/android/src/http_file_source.cpp | 14 | ||||
-rw-r--r-- | platform/android/src/offline/offline_region_error.cpp | 2 | ||||
-rw-r--r-- | platform/darwin/src/MGLOfflinePack.mm | 2 | ||||
-rw-r--r-- | platform/darwin/src/MGLOfflineStorage.mm | 16 | ||||
-rw-r--r-- | platform/node/src/node_mapbox_gl_native.cpp | 2 | ||||
-rw-r--r-- | platform/qt/src/http_request.cpp | 8 |
7 files changed, 55 insertions, 22 deletions
diff --git a/include/mbgl/storage/resource_error.hpp b/include/mbgl/storage/resource_error.hpp new file mode 100644 index 0000000000..82974c71c9 --- /dev/null +++ b/include/mbgl/storage/resource_error.hpp @@ -0,0 +1,33 @@ +#pragma once + +#include <mbgl/storage/resource_kind.hpp> +#include <mbgl/storage/resource_status.hpp> + +#include <stdexcept> + +namespace mbgl { +namespace util { + +struct ResourceError : public std::runtime_error { + explicit ResourceError(const char* what_arg, + const ResourceKind kind_, + const ResourceStatus status_, + const std::string& url_) + : std::runtime_error(what_arg), kind(kind_), status(status_), url(url_) { + } + explicit ResourceError(const std::string& what_arg, + const ResourceKind kind_, + const ResourceStatus status_, + const std::string& url_) + : std::runtime_error(what_arg), kind(kind_), status(status_), url(url_) { + } + + virtual ~ResourceError() = default; + + const ResourceKind kind; + const ResourceStatus status; + const std::string url; +}; + +} // namespace util +} // namespace mbgl diff --git a/platform/android/src/http_file_source.cpp b/platform/android/src/http_file_source.cpp index e8c2c87277..8a54b2917a 100644 --- a/platform/android/src/http_file_source.cpp +++ b/platform/android/src/http_file_source.cpp @@ -137,7 +137,7 @@ void HTTPRequest::onResponse(jni::JNIEnv& env, int code, } else if (code == 304) { response.notModified = true; } else if (code == 404) { - response.error = std::make_unique<Error>(ResourceStatus::NotFound, "HTTP status code 404"); + response.error = std::make_unique<Error>(ResourceStatus::NotFoundError, "HTTP status code 404"); } else if (code == 429) { optional<std::string> retryAfter; optional<std::string> xRateLimitReset; @@ -147,11 +147,11 @@ void HTTPRequest::onResponse(jni::JNIEnv& env, int code, if (jXRateLimitReset) { xRateLimitReset = jni::Make<std::string>(env, jXRateLimitReset); } - response.error = std::make_unique<Error>(ResourceStatus::RateLimit, "HTTP status code 429", http::parseRetryHeaders(retryAfter, xRateLimitReset)); + response.error = std::make_unique<Error>(ResourceStatus::RateLimitError, "HTTP status code 429", http::parseRetryHeaders(retryAfter, xRateLimitReset)); } else if (code >= 500 && code < 600) { - response.error = std::make_unique<Error>(ResourceStatus::Server, std::string{ "HTTP status code " } + std::to_string(code)); + response.error = std::make_unique<Error>(ResourceStatus::ServerError, std::string{ "HTTP status code " } + std::to_string(code)); } else { - response.error = std::make_unique<Error>(ResourceStatus::Other, std::string{ "HTTP status code " } + std::to_string(code)); + response.error = std::make_unique<Error>(ResourceStatus::OtherError, std::string{ "HTTP status code " } + std::to_string(code)); } async.send(); @@ -164,13 +164,13 @@ void HTTPRequest::onFailure(jni::JNIEnv& env, int type, jni::String message) { switch (type) { case connectionError: - response.error = std::make_unique<Error>(ResourceStatus::Connection, messageStr); + response.error = std::make_unique<Error>(ResourceStatus::ConnectionError, messageStr); break; case temporaryError: - response.error = std::make_unique<Error>(ResourceStatus::Server, messageStr); + response.error = std::make_unique<Error>(ResourceStatus::ServerError, messageStr); break; default: - response.error = std::make_unique<Error>(ResourceStatus::Other, messageStr); + response.error = std::make_unique<Error>(ResourceStatus::OtherError, messageStr); } async.send(); diff --git a/platform/android/src/offline/offline_region_error.cpp b/platform/android/src/offline/offline_region_error.cpp index 47f196e702..758c8b6395 100644 --- a/platform/android/src/offline/offline_region_error.cpp +++ b/platform/android/src/offline/offline_region_error.cpp @@ -7,7 +7,7 @@ jni::Object<OfflineRegionError> OfflineRegionError::New(jni::JNIEnv& env, mbgl:: // Handle the value of reason independently of the underlying int value std::string reason; - switch(error.reason) { + switch(error.status) { case mbgl::ResourceStatus::Success: reason = "REASON_SUCCESS"; break; diff --git a/platform/darwin/src/MGLOfflinePack.mm b/platform/darwin/src/MGLOfflinePack.mm index b6937f828c..775ed2061f 100644 --- a/platform/darwin/src/MGLOfflinePack.mm +++ b/platform/darwin/src/MGLOfflinePack.mm @@ -203,7 +203,7 @@ private: NSError *MGLErrorFromResponseError(mbgl::Response::Error error) { NSInteger errorCode = MGLErrorCodeUnknown; - switch (error.reason) { + switch (error.status) { case mbgl::ResourceStatus::NotFoundError: errorCode = MGLErrorCodeNotFound; break; diff --git a/platform/darwin/src/MGLOfflineStorage.mm b/platform/darwin/src/MGLOfflineStorage.mm index 2ddfa649e9..0efc025642 100644 --- a/platform/darwin/src/MGLOfflineStorage.mm +++ b/platform/darwin/src/MGLOfflineStorage.mm @@ -88,28 +88,28 @@ NSString * const MGLOfflinePackMaximumCountUserInfoKey = MGLOfflinePackUserInfoK encoding:NSUTF8StringEncoding]]; MGLResourceKind kind = MGLResourceKindUnknown; switch (kind_) { - case mbgl::Resource::Kind::Tile: + case mbgl::ResourceKind::Tile: kind = MGLResourceKindTile; break; - case mbgl::Resource::Kind::Glyphs: + case mbgl::ResourceKind::Glyphs: kind = MGLResourceKindGlyphs; break; - case mbgl::Resource::Kind::Style: + case mbgl::ResourceKind::Style: kind = MGLResourceKindStyle; break; - case mbgl::Resource::Kind::Source: + case mbgl::ResourceKind::Source: kind = MGLResourceKindSource; break; - case mbgl::Resource::Kind::SpriteImage: + case mbgl::ResourceKind::SpriteImage: kind = MGLResourceKindSpriteImage; break; - case mbgl::Resource::Kind::SpriteJSON: + case mbgl::ResourceKind::SpriteJSON: kind = MGLResourceKindSpriteJSON; break; - case mbgl::Resource::Kind::Image: + case mbgl::ResourceKind::Image: kind = MGLResourceKindImage; break; - case mbgl::Resource::Kind::Unknown: + case mbgl::ResourceKind::Unknown: kind = MGLResourceKindUnknown; break; diff --git a/platform/node/src/node_mapbox_gl_native.cpp b/platform/node/src/node_mapbox_gl_native.cpp index 47356f914b..dddd74aece 100644 --- a/platform/node/src/node_mapbox_gl_native.cpp +++ b/platform/node/src/node_mapbox_gl_native.cpp @@ -21,7 +21,7 @@ void RegisterModule(v8::Local<v8::Object> target, v8::Local<v8::Object> module) node_mbgl::NodeMap::Init(target); node_mbgl::NodeRequest::Init(); - // Exports Resource constants. + // Exports ResourceKind constants. v8::Local<v8::Object> resource = Nan::New<v8::Object>(); Nan::Set(resource, diff --git a/platform/qt/src/http_request.cpp b/platform/qt/src/http_request.cpp index 167f583cf4..d74ed0e7ee 100644 --- a/platform/qt/src/http_request.cpp +++ b/platform/qt/src/http_request.cpp @@ -66,7 +66,7 @@ void HTTPRequest::handleNetworkReply(QNetworkReply *reply) // Handle non-HTTP errors (i.e. like connection). if (reply->error() && reply->error() < 100) { response.error = std::make_unique<Error>( - ResourceStatus::Connection, reply->errorString().toStdString()); + ResourceStatus::ConnectionError, reply->errorString().toStdString()); callback(response); return; } @@ -115,18 +115,18 @@ void HTTPRequest::handleNetworkReply(QNetworkReply *reply) response.noContent = true; } else { response.error = std::make_unique<Error>( - ResourceStatus::NotFound, "HTTP status code 404"); + ResourceStatus::NotFoundError, "HTTP status code 404"); } break; } case 429: response.error = std::make_unique<Error>( - ResourceStatus::RateLimit, "HTTP status code 429", + ResourceStatus::RateLimitError, "HTTP status code 429", http::parseRetryHeaders(retryAfter, xRateLimitReset)); break; default: ResourceStatus reason = (responseCode >= 500 && responseCode < 600) ? - ResourceStatus::Server : ResourceStatus::Other; + ResourceStatus::ServerError : ResourceStatus::OtherError; response.error = std::make_unique<Error>( reason, "HTTP status code " + util::toString(responseCode)); |