diff options
Diffstat (limited to 'include/mbgl/storage/response.hpp')
-rw-r--r-- | include/mbgl/storage/response.hpp | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/include/mbgl/storage/response.hpp b/include/mbgl/storage/response.hpp index b5973457b5..8ab6170ba2 100644 --- a/include/mbgl/storage/response.hpp +++ b/include/mbgl/storage/response.hpp @@ -8,20 +8,47 @@ namespace mbgl { class Response { public: + Response() = default; + Response(const Response&); + Response& operator=(const Response&); + bool isExpired() const; public: - enum Status { Error, Successful, NotFound }; + class Error; + // When this object is empty, the response was successful. + std::unique_ptr<const Error> error; - Status status = Error; + // Stale responses are fetched from cache and are expired. bool stale = false; - std::string message; + + // The actual data of the response. This is guaranteed to never be empty. + std::shared_ptr<const std::string> data; + int64_t modified = 0; int64_t expires = 0; std::string etag; - std::shared_ptr<const std::string> data; }; -} +class Response::Error { +public: + enum class Reason : uint8_t { + // Success = 1, // Reserve 1 for Success. + NotFound = 2, + Server = 3, + Connection = 4, + Canceled = 5, + Other = 6, + } reason = Reason::Other; + + // An error message from the request handler, e.g. a server message or a system message + // informing the user about the reason for the failure. + std::string message; + +public: + Error(Reason, const std::string& = ""); +}; + +} // namespace mbgl #endif |