tizen 2.3.1 release
[framework/web/mobile/wrt-plugins-tizen.git] / src / Account / AccountUtil.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 #include "AccountUtil.h"
19
20 #include <sstream>
21
22 #include <PlatformException.h>
23 #include <Logger.h>
24
25 namespace DeviceAPI {
26 namespace Account {
27
28 using namespace DeviceAPI::Common;
29
30 void AccountUtil::throwAccountException(const int errorCode,
31                                         const std::string &hint)
32 {
33     LOGD("Enter");
34
35     std::stringstream ss;
36     ss << hint << " : " << getAccountErrorMessage(errorCode);
37     LOGE("%s", ss.str().c_str());
38
39     switch(errorCode) {
40         case ACCOUNT_ERROR_RECORD_NOT_FOUND:
41             throw NotFoundException(ss.str().c_str());
42         default:
43             throw UnknownException(ss.str().c_str());
44     }
45 }
46
47 std::string AccountUtil::getAccountErrorMessage(const int errorCode)
48 {
49     switch(errorCode) {
50         case ACCOUNT_ERROR_OUT_OF_MEMORY:
51             return "Out of Memory";
52         case ACCOUNT_ERROR_INVALID_PARAMETER:
53             return "Invalid Parameter";
54         case ACCOUNT_ERROR_DUPLICATED:
55             return "Same user name exists in your application";
56         case ACCOUNT_ERROR_NO_DATA:
57             return "Empty data";
58         case ACCOUNT_ERROR_RECORD_NOT_FOUND:
59             return "Related record does not exist";
60         case ACCOUNT_ERROR_DB_FAILED:
61             return "DB operation failed";
62         case ACCOUNT_ERROR_DB_NOT_OPENED:
63             return "DB is not connected";
64         case ACCOUNT_ERROR_QUERY_SYNTAX_ERROR:
65             return "DB query syntax error";
66         case ACCOUNT_ERROR_ITERATOR_END:
67             return "Iterator has reached the end";
68         case ACCOUNT_ERROR_NOTI_FAILED:
69             return "Notification failed";
70         case ACCOUNT_ERROR_PERMISSION_DENIED:
71             return "Permission denied";
72         case ACCOUNT_ERROR_XML_PARSE_FAILED:
73             return "XML parse failed";
74         case ACCOUNT_ERROR_XML_FILE_NOT_FOUND:
75             return "XML file does not exist";
76         case ACCOUNT_ERROR_EVENT_SUBSCRIPTION_FAIL:
77             return "Subscription failed";
78         case ACCOUNT_ERROR_NOT_REGISTERED_PROVIDER:
79             return "Account provider is not registered";
80         case ACCOUNT_ERROR_NOT_ALLOW_MULTIPLE:
81             return "Multiple accounts are not supported";
82         case ACCOUNT_ERROR_DATABASE_BUSY:
83             return "SQLite busy handler expired";
84         default:
85             return "Unknown Error";
86     }
87 }
88
89 } // Account
90 } // DeviceAPI