1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "web_errors.h"
17
18 #include <string>
19 #include <unordered_map>
20
21 namespace {
22 // error message
23 const std::string PARAM_CHECK_ERROR_MSG = "Invalid input parameter";
24 const std::string INIT_ERROR_MSG = "Init error. The WebviewController must be associated with a Web component";
25 const std::string INVALID_URL_MSG = "Invalid url";
26 const std::string INVALID_RESOURCE_MSG = "Invalid resource path or file type";
27 const std::string FUNCTION_NOT_ENABLE_MSG = "Function not enable";
28 const std::string INVALID_COOKIE_VALUE_MSG = "Invalid cookie value";
29 const std::string CAN_NOT_REGISTER_MESSAGE_EVENT_MSG = "Can not register message event using this port";
30 const std::string CANNOT_DEL_JAVA_SCRIPT_PROXY_MSG = "Cannot delete JavaScriptProxy.";
31 const std::string CAN_NOT_POST_MESSAGE_MSG = "Can not post message using this port";
32 const std::string INVALID_ORIGIN_MSG = "Invalid origin";
33 const std::string NO_WEBSTORAGE_ORIGIN_MSG = "Invalid web storage origin";
34 const std::string INVALID_SOCKET_NUMBER_MSG = "The number of preconnect sockets is invalid.";
35 const std::string TYPE_NOT_MATCH_WITCH_VALUE_MSG = "The type does not match with the value of the message";
36 const std::string NEW_OOM_MSG = "New failed, out of memory";
37 }
38
39 namespace OHOS {
40 namespace NWebError {
41 std::unordered_map<ErrCode, std::string> g_errCodeMsgMap = {
42 {PARAM_CHECK_ERROR, PARAM_CHECK_ERROR_MSG},
43 {INIT_ERROR, INIT_ERROR_MSG},
44 {INVALID_URL, INVALID_URL_MSG},
45 {INVALID_RESOURCE, INVALID_RESOURCE_MSG},
46 {FUNCTION_NOT_ENABLE, FUNCTION_NOT_ENABLE_MSG},
47 {INVALID_COOKIE_VALUE, INVALID_COOKIE_VALUE_MSG},
48 {CAN_NOT_REGISTER_MESSAGE_EVENT, CAN_NOT_REGISTER_MESSAGE_EVENT_MSG},
49 {CANNOT_DEL_JAVA_SCRIPT_PROXY, CANNOT_DEL_JAVA_SCRIPT_PROXY_MSG},
50 {CAN_NOT_POST_MESSAGE, CAN_NOT_POST_MESSAGE_MSG},
51 {INVALID_ORIGIN, INVALID_ORIGIN_MSG},
52 {NO_WEBSTORAGE_ORIGIN, NO_WEBSTORAGE_ORIGIN_MSG},
53 {INVALID_SOCKET_NUMBER, INVALID_SOCKET_NUMBER_MSG},
54 {TYPE_NOT_MATCH_WITCH_VALUE, TYPE_NOT_MATCH_WITCH_VALUE_MSG},
55 {NEW_OOM, NEW_OOM_MSG}
56 };
57
GetErrMsgByErrCode(ErrCode code)58 std::string GetErrMsgByErrCode(ErrCode code)
59 {
60 return g_errCodeMsgMap[code];
61 }
62 } // namespace NWebError
63 } // namespace OHOS