Commit 4bb7cf08 authored by Paweł Wegner's avatar Paweł Wegner
Browse files

Request: added error callback.

parent ecb0d2bf
......@@ -57,6 +57,11 @@ void Request<T>::set_resolver(Resolver resolver) {
function_ = std::async(std::launch::async, std::bind(resolver, this));
}
template <class T>
void Request<T>::set_error_callback(ErrorCallback f) {
error_callback_ = f;
}
template <class T>
void Request<T>::finish() {
std::shared_future<T> future = function_;
......@@ -108,7 +113,9 @@ bool Request<T>::reauthorize() {
}
template <class T>
void Request<T>::error(int, const std::string&) {}
void Request<T>::error(int code, const std::string& desc) {
if (error_callback_) error_callback_(code, desc);
}
template <class T>
std::string Request<T>::error_string(int code, const std::string& desc) const {
......
......@@ -43,10 +43,12 @@ class Request : public IRequest<ReturnValue> {
public:
using ProgressFunction = std::function<void(uint32_t, uint32_t)>;
using Resolver = std::function<ReturnValue(Request*)>;
using ErrorCallback = std::function<void(int, const std::string&)>;
Request(std::shared_ptr<CloudProvider>);
void set_resolver(Resolver);
void set_error_callback(ErrorCallback);
void finish();
void cancel();
......@@ -60,7 +62,6 @@ class Request : public IRequest<ReturnValue> {
std::ostream* error, ProgressFunction download = nullptr,
ProgressFunction upload = nullptr);
protected:
std::shared_ptr<CloudProvider> provider() const { return provider_; }
virtual void error(int code, const std::string& description);
std::string error_string(int code, const std::string& desc) const;
......@@ -77,6 +78,7 @@ class Request : public IRequest<ReturnValue> {
std::shared_ptr<CloudProvider> provider_;
std::atomic_bool is_cancelled_;
std::shared_future<ReturnValue> function_;
ErrorCallback error_callback_;
};
} // namespace cloudstorage
......
Supports Markdown
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