[Download] Added information about HTTP status in error message 05/153905/3
authorPiotr Kosko <p.kosko@samsung.com>
Tue, 3 Oct 2017 06:29:50 +0000 (08:29 +0200)
committerPiotr Kosko <p.kosko@samsung.com>
Wed, 11 Oct 2017 09:42:27 +0000 (11:42 +0200)
[Feature] Error message of onfailed callback of start method, return only
  Unknown error. Now information about HTTP status was added into message.

[Verification] Checked in chrome console.
  TCT passrate - 100%.

Change-Id: I157053d10a1e770c070b55465f1a7351c0c80cce
Signed-off-by: Piotr Kosko <p.kosko@samsung.com>
src/download/download_instance.cc
src/download/download_instance.h

index 3ea612b..208caae 100644 (file)
@@ -23,9 +23,9 @@
 #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 {
@@ -109,90 +109,69 @@ bool DownloadInstance::CheckInstance(DownloadInstance* instance) {
   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.");
   }
 }
 
@@ -432,9 +411,17 @@ gboolean DownloadInstance::OnFailed(void* user_data) {
   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)));
   }
 
@@ -530,8 +517,8 @@ void DownloadInstance::DownloadManagerStart(const picojson::value& args, picojso
 
   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;
   }
 
index a951c9e..f628736 100644 (file)
@@ -56,7 +56,7 @@ class DownloadInstance : public common::ParsedInstance {
 
   bool GetDownloadID(const int callback_id, int& download_id);
 
-  static common::PlatformResult convertError(int err);
+  static common::PlatformResult convertError(int err, const std::string& message = "");
   static void OnStateChanged(int download_id, download_state_e state, void* user_data);
   static void progress_changed_cb(int download_id, long long unsigned received, void* user_data);
   static void OnStart(int download_id, void* user_data);