From: Kamil Lysik Date: Wed, 18 Feb 2015 15:43:31 +0000 (+0100) Subject: [Filesystem] Refactor: Add PrepareError function X-Git-Tag: submit/tizen_tv/20150603.064601~1^2~394^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9ad21859e0e57f8f04e5e6bce923fa84d13470cb;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Filesystem] Refactor: Add PrepareError function This function is used to report Filesystem errors in unified way. Change-Id: I9a197ca19d4202b3ed3b3d110587cd4e86f76fdf Signed-off-by: Kamil Lysik --- diff --git a/src/filesystem/filesystem_instance.cc b/src/filesystem/filesystem_instance.cc index a6aa27fa..23f6dfdd 100644 --- a/src/filesystem/filesystem_instance.cc +++ b/src/filesystem/filesystem_instance.cc @@ -70,20 +70,7 @@ void FilesystemInstance::FileStat(const picojson::value& args, picojson::value response = picojson::value(picojson::object()); picojson::object& obj = response.get(); obj["callbackId"] = picojson::value(callback_id); - switch (e) { - case FilesystemError::None: - ReportError(UnknownException("PLATFORM ERROR"), obj); - break; - case FilesystemError::NotFound: - ReportError(NotFoundException("PLATFORM ERROR"), obj); - break; - case FilesystemError::Other: - ReportError(UnknownException("PLATFORM ERROR"), obj); - break; - default: - ReportError(UnknownException("PLATFORM ERROR"), obj); - break; - } + PrepareError(e, obj); PostMessage(response.serialize().c_str()); }; @@ -106,20 +93,7 @@ void FilesystemInstance::FileStatSync(const picojson::value& args, auto onError = [&](FilesystemError e) { LoggerD("enter"); - switch (e) { - case FilesystemError::None: - ReportError(UnknownException("PLATFORM ERROR"), out); - break; - case FilesystemError::NotFound: - ReportError(NotFoundException("PLATFORM ERROR"), out); - break; - case FilesystemError::Other: - ReportError(UnknownException("PLATFORM ERROR"), out); - break; - default: - ReportError(UnknownException("PLATFORM ERROR"), out); - break; - } + PrepareError(e, out); }; FilesystemManager::GetInstance().StatPath(location, onSuccess, onError); @@ -140,20 +114,7 @@ void FilesystemInstance::FilesystemGetWidgetPaths(const picojson::value& args, auto onError = [&](FilesystemError e) { LoggerD("enter"); - switch (e) { - case FilesystemError::None: - ReportError(UnknownException("PLATFORM ERROR"), out); - break; - case FilesystemError::NotFound: - ReportError(NotFoundException("PLATFORM ERROR"), out); - break; - case FilesystemError::Other: - ReportError(UnknownException("PLATFORM ERROR"), out); - break; - default: - ReportError(UnknownException("PLATFORM ERROR"), out); - break; - } + PrepareError(e, out); }; FilesystemManager::GetInstance().GetWidgetPaths(onSuccess, onError); @@ -176,25 +137,34 @@ void FilesystemInstance::FileSystemManagerFetchStorages( auto onError = [&](FilesystemError e) { LoggerD("enter"); - switch (e) { - case FilesystemError::None: - ReportError(UnknownException("PLATFORM ERROR"), out); - break; - case FilesystemError::NotFound: - ReportError(NotFoundException("PLATFORM ERROR"), out); - break; - case FilesystemError::Other: - ReportError(UnknownException("PLATFORM ERROR"), out); - break; - default: - ReportError(UnknownException("PLATFORM ERROR"), out); - break; - } + PrepareError(e, out); }; FilesystemManager::GetInstance().FetchStorages(onSuccess, onError); } +void FilesystemInstance::PrepareError(const FilesystemError& error, picojson::object& out) +{ + LoggerD("enter"); + switch (error) { + case FilesystemError::None: + ReportError(UnknownException("PLATFORM ERROR"), out); + break; + case FilesystemError::NotFound: + ReportError(NotFoundException("PLATFORM ERROR"), out); + break; + case FilesystemError::PermissionDenied: + ReportError(IOException("Permission denied"), out); + break; + case FilesystemError::Other: + ReportError(UnknownException("PLATFORM ERROR"), out); + break; + default: + ReportError(UnknownException("PLATFORM ERROR"), out); + break; + } +} + #undef CHECK_EXIST } // namespace filesystem diff --git a/src/filesystem/filesystem_instance.h b/src/filesystem/filesystem_instance.h index 9b29cdf0..94ee6702 100644 --- a/src/filesystem/filesystem_instance.h +++ b/src/filesystem/filesystem_instance.h @@ -6,6 +6,7 @@ #define FILESYSTEM_FILESYSTEM_INSTANCE_H_ #include "common/extension.h" +#include "filesystem_utils.h" namespace extension { namespace filesystem { @@ -22,6 +23,8 @@ class FilesystemInstance : public common::ParsedInstance { picojson::object& out); void FileSystemManagerFetchStorages(const picojson::value& args, picojson::object& out); + + void PrepareError(const FilesystemError& error, picojson::object& out); }; } // namespace filesystem