2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
22 #ifndef _TIZEN_FILESYSTEM_JSERRORS_H_
23 #define _TIZEN_FILESYSTEM_JSERRORS_H_
27 #include <CommonsJavaScript/JSCallbackManager.h>
28 #include <JSWebAPIErrorFactory.h>
31 #include "FilesystemUtils.h"
34 namespace Filesystem {
36 bool checkReportAsync(
37 const std::string& aName,
38 const std::string& aMessage,
39 WrtDeviceApis::CommonsJavaScript::JSCallbackManagerPtr aCallback,
40 JSContextRef aContext);
42 template <class UserData>
43 inline bool checkReportAsyncAPI(
44 const std::string& aName,
45 const std::string& aMessage,
46 std::shared_ptr<UserData> aCallback,
47 JSContextRef aContext)
49 LOGD("Error mode check for [%s]", aName.c_str());
50 bool mode = "InvalidValuesError" == aName ||
52 "UnknownError" == aName ||
53 "NotFoundError" == aName;
56 LOGD("Asynchronous error report for Name:[%s] Message[%s]",
57 aName.c_str(), aMessage.c_str());
58 Utils::MainLoop<std::shared_ptr<UserData> >::passErrorLater(
61 JSValueMakeUndefined(aContext),
67 std::string translateApi2APIErrors(const std::string& aApiError);
69 template <class taEvent>
70 inline void reportErrorCode(const taEvent& aEvent,
71 const std::string& aErrorName,
72 const std::string& aMessage)
74 using namespace WrtDeviceApis::Commons;
75 ExceptionCodes::Enumeration exceptionCode;
76 if ("TypeMismatchError" == aErrorName) {
77 exceptionCode = ExceptionCodes::InvalidArgumentException;
78 } else if ("InvalidValuesError" == aErrorName) {
79 exceptionCode = ExceptionCodes::PlatformException;
80 } else if ("IOError" == aErrorName) {
81 exceptionCode = ExceptionCodes::InvalidArgumentException;
82 } else if ("UnknownError" == aErrorName) {
83 exceptionCode = ExceptionCodes::UnknownException;
84 } else if ("ServiceNotAvailableError" == aErrorName) {
85 exceptionCode = ExceptionCodes::PlatformException;
86 } else if ("SecurityError" == aErrorName) {
87 exceptionCode = ExceptionCodes::SecurityException;
88 } else if ("NotSupportedError" == aErrorName) {
89 exceptionCode = ExceptionCodes::UnsupportedException;
90 } else if ("NotFoundError" == aErrorName) {
91 exceptionCode = ExceptionCodes::NotFoundException;
92 } else if ("InvalidAccessError" == aErrorName) {
93 exceptionCode = ExceptionCodes::SecurityException;
94 } else if ("QuotaExceededError" == aErrorName) {
95 exceptionCode = ExceptionCodes::PlatformException;
97 exceptionCode = ExceptionCodes::UnknownException;
99 LOGD("Exception %s message %s translated to code %d ",
103 aEvent->setExceptionCode(exceptionCode);
109 #endif //ifndef _TIZEN_FILESYSTEM_JSERRORS_H_