• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef ERROR_UTIL_H
16 #define ERROR_UTIL_H
17 
18 #include <string>
19 
20 #include "napi/native_api.h"
21 #include "napi/native_node_api.h"
22 
23 namespace OHOS {
24 namespace Global {
25 namespace I18n {
26 // Common error code
27 const int32_t I18N_NO_PERMISSION  = 201;          // The app doesn't have requested permission
28 const int32_t I18N_NOT_SYSTEM_APP = 202;          // The app isn't a system app
29 const int32_t I18N_NOT_FOUND     = 401;          // Input parameter is missing
30 
31 // I18N error code
32 const int32_t I18N_NOT_VALID  = 890001;    // Unsupported para value
33 const int32_t I18N_NOT_VALID_NEW  = 8900001;    // Unsupported para value
34 const int32_t I18N_OPTION_NOT_VALID   = 890002;    // Unsupported option value
35 const size_t FUNC_ARGS_COUNT = 2;    // Function input parameter count
36 
37 class ErrorUtil {
38 public:
39     static void NapiThrow(napi_env env, int32_t errCode, const std::string& valueName,
40         const std::string& valueContent, bool throwError);
41     static void NapiNotFoundError(napi_env env, int32_t errCode, const std::string& valueName,
42         bool throwError);
43     static void NapiThrowUndefined(napi_env env, const std::string& value);
44 };
45 } // namespace I18n
46 } // namespace Global
47 } // namespace OHOS
48 #endif