• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 <unordered_map>
17 #include "devattest_errno.h"
18 #include "devattest_napi_error.h"
19 
20 namespace OHOS {
21 namespace DevAttest {
22 static const std::unordered_map<uint32_t, std::string> g_errorStringMap = {
23     {DEVATTEST_ERR_JS_IS_NOT_SYSTEM_APP,
24         "This api is system api, Please use the system application to call this api"},
25     {DEVATTEST_ERR_JS_PARAMETER_ERROR, "Input paramters wrong"},
26     {DEVATTEST_ERR_JS_SYSTEM_SERVICE_EXCEPTION, "System service exception, please try again or reboot your device"},
27 };
28 
ConvertToJsErrCode(int32_t errCode)29 int32_t ConvertToJsErrCode(int32_t errCode)
30 {
31     int32_t jsErrCode = errCode;
32     if (jsErrCode == DEVATTEST_FAIL) {
33         jsErrCode = DEVATTEST_ERR_JS_SYSTEM_SERVICE_EXCEPTION;
34     }
35     return jsErrCode;
36 }
37 
ConvertToJsErrMsg(int32_t jsErrCode)38 std::string ConvertToJsErrMsg(int32_t jsErrCode)
39 {
40     auto iter = g_errorStringMap.find(jsErrCode);
41     if (iter != g_errorStringMap.end()) {
42         return iter->second;
43     } else {
44         return "Unknown error, please reboot your device and try again";
45     }
46 }
47 } // namespace DevAttest
48 } // namespace OHOS
49