Fix error code in on_upload_error/on_download_error.

This commit is contained in:
levlam 2022-09-20 02:02:28 +03:00
parent ee381ecbb5
commit 097f3d42e1
7 changed files with 26 additions and 22 deletions

View File

@ -9052,7 +9052,7 @@ void MessagesManager::on_upload_media_error(FileId file_id, Status status) {
bool is_edit = full_message_id.get_message_id().is_any_server();
if (is_edit) {
fail_edit_message_media(full_message_id, Status::Error(status.code() > 0 ? status.code() : 500, status.message()));
fail_edit_message_media(full_message_id, std::move(status));
} else {
fail_send_message(full_message_id, std::move(status));
}

View File

@ -258,7 +258,7 @@ class WebFileDownloadGenerateActor final : public FileGenerateActor {
}
void hangup_shared() final {
on_error(Status::Error(1, "Canceled"));
on_error(Status::Error(-1, "Canceled"));
}
};
@ -328,7 +328,7 @@ class FileExternalGenerateActor final : public FileGenerateActor {
static_cast<int64>(query_id_), generate_location_.original_path_, path_, generate_location_.conversion_));
}
void hangup() final {
check_status(Status::Error(1, "Canceled"));
check_status(Status::Error(-1, "Canceled"));
}
Status do_file_generate_write_part(int64 offset, const string &data) {
@ -365,7 +365,7 @@ class FileExternalGenerateActor final : public FileGenerateActor {
void check_status(Status status, Promise<> promise = Promise<>()) {
if (promise) {
if (status.is_ok() || status.code() == 1) {
if (status.is_ok() || status.code() == -1) {
promise.set_value(Unit());
} else {
promise.set_error(Status::Error(400, status.message()));

View File

@ -156,7 +156,7 @@ void FileLoadManager::cancel(QueryId id) {
if (it == query_id_to_node_id_.end()) {
return;
}
on_error_impl(it->second, Status::Error(1, "Canceled"));
on_error_impl(it->second, Status::Error(-1, "Canceled"));
}
void FileLoadManager::update_local_file_location(QueryId id, const LocalFileLocation &local) {
if (stop_flag_) {
@ -298,7 +298,7 @@ void FileLoadManager::on_error_impl(NodeId node_id, Status status) {
void FileLoadManager::hangup_shared() {
auto node_id = get_link_token();
on_error_impl(node_id, Status::Error(1, "Canceled"));
on_error_impl(node_id, Status::Error(-1, "Canceled"));
}
void FileLoadManager::loop() {

View File

@ -153,7 +153,7 @@ void FileLoader::loop() {
}
auto status = do_loop();
if (status.is_error()) {
if (status.code() == 1) {
if (status.code() == -1) {
return;
}
on_error(std::move(status));

View File

@ -2193,7 +2193,7 @@ void FileManager::download(FileId file_id, std::shared_ptr<DownloadCallback> cal
if (!node) {
LOG(INFO) << "File " << file_id << " not found";
if (callback) {
callback->on_download_error(file_id, Status::Error("File not found"));
callback->on_download_error(file_id, Status::Error(400, "File not found"));
}
return;
}
@ -2220,7 +2220,7 @@ void FileManager::download(FileId file_id, std::shared_ptr<DownloadCallback> cal
if (!file_view.can_download_from_server() && !file_view.can_generate()) {
LOG(INFO) << "File " << file_id << " can't be downloaded";
if (callback) {
callback->on_download_error(file_id, Status::Error("Can't download or generate file"));
callback->on_download_error(file_id, Status::Error(400, "Can't download or generate file"));
}
return;
}
@ -2439,7 +2439,7 @@ class FileManager::ForceUploadActor final : public Actor {
if (callback_.empty()) {
return;
}
send_closure(std::move(callback_), &ForceUploadActor::on_upload_error, Status::Error("Canceled"));
send_closure(std::move(callback_), &ForceUploadActor::on_upload_error, Status::Error(200, "Canceled"));
}
private:
@ -2517,7 +2517,7 @@ class FileManager::ForceUploadActor final : public Actor {
void tear_down() final {
if (callback_) {
callback_->on_upload_error(file_id_, Status::Error("Canceled"));
callback_->on_upload_error(file_id_, Status::Error(200, "Canceled"));
}
}
};
@ -2536,7 +2536,7 @@ void FileManager::resume_upload(FileId file_id, vector<int> bad_parts, std::shar
if (!node) {
LOG(INFO) << "File " << file_id << " not found";
if (callback) {
callback->on_upload_error(file_id, Status::Error("File not found"));
callback->on_upload_error(file_id, Status::Error(400, "File not found"));
}
return;
}
@ -2545,7 +2545,7 @@ void FileManager::resume_upload(FileId file_id, vector<int> bad_parts, std::shar
if (node->last_successful_force_reupload_time_ >= Time::now() - 60) {
LOG(INFO) << "Recently reuploaded file " << file_id << ", do not try again";
if (callback) {
callback->on_upload_error(file_id, Status::Error("Failed to reupload file"));
callback->on_upload_error(file_id, Status::Error(400, "Failed to reupload file"));
}
return;
}
@ -2585,8 +2585,8 @@ void FileManager::resume_upload(FileId file_id, vector<int> bad_parts, std::shar
if (!file_view.has_local_location() && !file_view.has_generate_location() && !file_view.has_alive_remote_location()) {
LOG(INFO) << "File " << file_id << " can't be uploaded";
if (callback) {
callback->on_upload_error(file_id,
Status::Error("Need full local (or generate, or inactive remote) location for upload"));
callback->on_upload_error(
file_id, Status::Error(400, "Need full local (or generate, or inactive remote) location for upload"));
}
return;
}
@ -2594,7 +2594,7 @@ void FileManager::resume_upload(FileId file_id, vector<int> bad_parts, std::shar
(!file_view.has_local_location() && file_view.can_download_from_server())) {
// TODO
if (callback) {
callback->on_upload_error(file_id, Status::Error("Failed to upload thumbnail without local location"));
callback->on_upload_error(file_id, Status::Error(400, "Failed to upload thumbnail without local location"));
}
return;
}
@ -3854,9 +3854,13 @@ void FileManager::on_error_impl(FileNodePtr node, Query::Type type, bool was_act
return;
}
if (status.code() != 1 && !G()->close_flag()) {
LOG(WARNING) << "Failed to " << type << " file " << node->main_file_id_ << " of type " << FileView(node).get_type()
<< ": " << status;
if (G()->close_flag() && status.code() < 400) {
status = Global::request_aborted_error();
} else {
if (status.code() != -1) {
LOG(WARNING) << "Failed to " << type << " file " << node->main_file_id_ << " of type "
<< FileView(node).get_type() << ": " << status;
}
if (status.code() == 0) {
// Remove partial locations
if (node->local_.type() == LocalFileLocation::Type::Partial &&
@ -3872,8 +3876,8 @@ void FileManager::on_error_impl(FileNodePtr node, Query::Type type, bool was_act
}
}
node->delete_partial_remote_location();
status = Status::Error(400, status.message());
}
status = Status::Error(400, status.message());
}
// Stop everything on error

View File

@ -239,7 +239,7 @@ Status FileUploader::generate_iv_map() {
Status FileUploader::before_start_parts() {
auto status = acquire_fd();
if (status.is_error() && !local_is_ready_) {
return Status::Error(1, "Can't open temporary file");
return Status::Error(-1, "Can't open temporary file");
}
return status;
}

View File

@ -281,7 +281,7 @@ Result<Part> PartsManager::start_part() {
update_first_empty_part();
auto part_i = first_streaming_empty_part_;
if (known_prefix_flag_ && part_i >= static_cast<int>(known_prefix_size_ / part_size_)) {
return Status::Error(1, "Wait for prefix to be known");
return Status::Error(-1, "Wait for prefix to be known");
}
if (part_i == part_count_) {
if (unknown_size_flag_) {