#include "common/filesystem/filesystem_provider.h"
#include "common/logger.h"
#include "common/picojson.h"
+#include "common/scope_exit.h"
#include "common/tools.h"
#include "common/typeutil.h"
-#include "common/scope_exit.h"
namespace extension {
namespace download {
return false;
}
-common::PlatformResult DownloadInstance::convertError(int err) {
- char* error = get_error_message(err);
+common::PlatformResult DownloadInstance::convertError(int err, const std::string& message) {
+ char* error = nullptr;
+ if (message.empty()) {
+ error = get_error_message(err);
+ } else {
+ error = (char*)message.c_str();
+ }
+
switch (err) {
case DOWNLOAD_ERROR_INVALID_PARAMETER:
- return LogAndCreateResult(common::ErrorCode::INVALID_VALUES_ERR, error,
- ("Error %d (%s)", err, error));
+ return common::PlatformResult(common::ErrorCode::INVALID_VALUES_ERR, error);
case DOWNLOAD_ERROR_OUT_OF_MEMORY:
- return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, error,
- ("Error %d (%s)", err, error));
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, error);
case DOWNLOAD_ERROR_NETWORK_UNREACHABLE:
- return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, error,
- ("Error %d (%s)", err, error));
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, error);
case DOWNLOAD_ERROR_CONNECTION_TIMED_OUT:
- return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, error,
- ("Error %d (%s)", err, error));
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, error);
case DOWNLOAD_ERROR_NO_SPACE:
- return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, error,
- ("Error %d (%s)", err, error));
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, error);
case DOWNLOAD_ERROR_PERMISSION_DENIED:
- return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, error,
- ("Error %d (%s)", err, error));
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, error);
case DOWNLOAD_ERROR_NOT_SUPPORTED:
- return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, error,
- ("Error %d (%s)", err, error));
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, error);
case DOWNLOAD_ERROR_INVALID_STATE:
- return LogAndCreateResult(common::ErrorCode::INVALID_VALUES_ERR, error,
- ("Error %d (%s)", err, error));
+ return common::PlatformResult(common::ErrorCode::INVALID_VALUES_ERR, error);
case DOWNLOAD_ERROR_CONNECTION_FAILED:
- return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, error,
- ("Error %d (%s)", err, error));
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, error);
case DOWNLOAD_ERROR_INVALID_URL:
- return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, error,
- ("Error %d (%s)", err, error));
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, error);
case DOWNLOAD_ERROR_INVALID_DESTINATION:
- return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, error,
- ("Error %d (%s)", err, error));
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, error);
case DOWNLOAD_ERROR_TOO_MANY_DOWNLOADS:
- return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, error,
- ("Error %d (%s)", err, error));
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, error);
case DOWNLOAD_ERROR_QUEUE_FULL:
- return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, error,
- ("Error %d (%s)", err, error));
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, error);
case DOWNLOAD_ERROR_ALREADY_COMPLETED:
- return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, error,
- ("Error %d (%s)", err, error));
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, error);
case DOWNLOAD_ERROR_FILE_ALREADY_EXISTS:
- return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, error,
- ("Error %d (%s)", err, error));
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, error);
case DOWNLOAD_ERROR_CANNOT_RESUME:
- return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, error,
- ("Error %d (%s)", err, error));
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, error);
case DOWNLOAD_ERROR_FIELD_NOT_FOUND:
- return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, error,
- ("Error %d (%s)", err, error));
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, error);
case DOWNLOAD_ERROR_TOO_MANY_REDIRECTS:
- return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, error,
- ("Error %d (%s)", err, error));
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, error);
case DOWNLOAD_ERROR_UNHANDLED_HTTP_CODE:
- return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, error,
- ("Error %d (%s)", err, error));
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, error);
case DOWNLOAD_ERROR_REQUEST_TIMEOUT:
- return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, error,
- ("Error %d (%s)", err, error));
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, error);
case DOWNLOAD_ERROR_RESPONSE_TIMEOUT:
- return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, error,
- ("Error %d (%s)", err, error));
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, error);
case DOWNLOAD_ERROR_SYSTEM_DOWN:
- return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, error,
- ("Error %d (%s)", err, error));
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, error);
case DOWNLOAD_ERROR_ID_NOT_FOUND:
- return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, error,
- ("Error %d (%s)", err, error));
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, error);
case DOWNLOAD_ERROR_INVALID_NETWORK_TYPE:
- return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, error,
- ("Error %d (%s)", err, error));
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, error);
case DOWNLOAD_ERROR_NO_DATA:
- return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, error,
- ("Error %d (%s)", err, error));
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, error);
case DOWNLOAD_ERROR_IO_ERROR:
- return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, error,
- ("Error %d (%s)", err, error));
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, error);
default:
- return LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, "Unknown error.",
- ("Unknown error: %d", err));
+ return common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, "Unknown error.");
}
}
LoggerD("OnFailed for callbackID %d called", callback_id);
download_get_error(downCbPtr->downloadId, &error);
-
if (DOWNLOAD_ERROR_NONE != error) {
- LogAndReportError(convertError(error), &out,
+ int http_status = 0;
+ int ret = download_get_http_status(downCbPtr->downloadId, &http_status);
+ std::string error_message;
+ if (DOWNLOAD_ERROR_NONE != ret) {
+ LoggerE("Gathering HTTP status failed, default error message will be used");
+ } else {
+ LoggerD("HTTP status is: %d", http_status);
+ error_message = "Error with HTTP status: " + std::to_string(http_status);
+ }
+ LogAndReportError(convertError(error, error_message), &out,
("download_get_error error: %d (%s)", error, get_error_message(error)));
}
if (CONNECTION_TYPE_DISCONNECTED == connection_type) {
LogAndReportError(
- common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, "Connection problem occured"),
- &out, ("Connection type is disconnected"));
+ common::PlatformResult(common::ErrorCode::UNKNOWN_ERR, "Connection problem occured"), &out,
+ ("Connection type is disconnected"));
return;
}