!563 增加js提示信息

Merge pull request !563 from 王移波/master
This commit is contained in:
openharmony_ci
2022-05-24 10:04:06 +00:00
committed by Gitee
5 changed files with 106 additions and 0 deletions
@@ -25,6 +25,7 @@
#include "dm_native_event.h"
#include "dm_subscribe_info.h"
#include "dm_anonymous.h"
#include "dm_error_message.h"
#include "napi/native_api.h"
#include "napi/native_node_api.h"
#include "nlohmann/json.hpp"
@@ -473,6 +473,8 @@ void DeviceManagerNapi::OnDiscoveryFailed(uint16_t subscribeId, int32_t failedRe
napi_create_object(env_, &result);
SetValueInt32(env_, "subscribeId", (int)subscribeId, result);
SetValueInt32(env_, "reason", (int)failedReason, result);
std::string errCodeInfo = OHOS::DistributedHardware::GetErrorString((int)failedReason);
SetValueUtf8String(env_, "errInfo", errCodeInfo, result);
OnEvent("discoverFail", DM_NAPI_ARGS_ONE, &result);
}
@@ -494,6 +496,8 @@ void DeviceManagerNapi::OnAuthResult(const std::string &deviceId, const std::str
napi_create_object(env_, &result[0]);
SetValueInt32(env_, "code", status, result[0]);
SetValueInt32(env_, "reason", reason, result[0]);
std::string errCodeInfo = OHOS::DistributedHardware::GetErrorString((int)reason);
SetValueUtf8String(env_, "errInfo", errCodeInfo, result[0]);
napi_get_undefined(env_, &result[1]);
}
+3
View File
@@ -41,6 +41,7 @@ if (defined(ohos_lite)) {
sources = [
"${utils_path}/src/dm_anonymous.cpp",
"${utils_path}/src/dm_error_message.cpp",
"${utils_path}/src/dm_log.cpp",
"${utils_path}/src/dm_random.cpp",
"${utils_path}/src/permission/lite/permission_manager.cpp",
@@ -91,6 +92,7 @@ if (defined(ohos_lite)) {
]
sources = [
"src/dm_anonymous.cpp",
"src/dm_error_message.cpp",
"src/dm_log.cpp",
"src/dm_random.cpp",
"src/fwkload/lite/dm_distributed_hardware_load.cpp",
@@ -131,6 +133,7 @@ if (defined(ohos_lite)) {
ohos_shared_library("devicemanagerutils") {
sources = [
"src/dm_anonymous.cpp",
"src/dm_error_message.cpp",
"src/dm_hash.cpp",
"src/dm_log.cpp",
"src/dm_random.cpp",
+29
View File
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_DM_ERROMSG_H
#define OHOS_DM_ERROMSG_H
#include "dm_log.h"
#include "dm_constants.h"
#include <string>
namespace OHOS {
namespace DistributedHardware {
std::string GetErrorString(int failedReason);
} // namespace DistributedHardware
} // namespace OHOS
#endif // OHOS_DM_ERROMSG_H
+69
View File
@@ -0,0 +1,69 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "dm_error_message.h"
namespace OHOS {
namespace DistributedHardware {
typedef struct ERROR_INFO {
int errCode;
std::string errMsg;
} ERROR_INFO;
static ERROR_INFO g_errorMessages[] = {
{ERR_DM_FAILED, "dm process execution failed."},
{ERR_DM_TIME_OUT, "dm process execution timeout."},
{ERR_DM_NOT_INIT, "dm service is not initialized, please try again later."},
{ERR_DM_INIT_REPEATED, "dm service repeated initialization."},
{ERR_DM_INIT_FAILED, "dm service initialize failed."},
{ERR_DM_UNINIT_FAILED, "dm Service uninitialization failed."},
{ERR_DM_POINT_NULL, "dm service null pointer exception occurred."},
{ERR_DM_INPUT_PARAMETER_EMPTY, "the function call input parameter is empty."},
{ERR_DM_NO_PERMISSION, "no permission for function call."},
{ERR_DM_MALLOC_FAILED, "memory allocation failed."},
{ERR_DM_DISCOVERY_FAILED, "device discovery failed."},
{ERR_DM_MAP_KEY_ALREADY_EXISTS, "map key already exists."},
{DM_PROFILE_EVENTS_FAILED, "process profile events failed."},
{ERR_DM_IPC_WRITE_FAILED, "ipc write object failed."},
{ERR_DM_IPC_COPY_FAILED, "ipc copy data failed."},
{ERR_DM_IPC_SEND_REQUEST_FAILED, "ipc send request failed."},
{ERR_DM_UNSUPPORTED_IPC_COMMAND, "ipc command not supported."},
{ERR_DM_IPC_RESPOND_FAILED, "ipc process failed to receive response."},
{ERR_DM_IPC_WRITE_TOKEN_FAILED, "ipc write token failed."},
{ERR_DM_DISCOVERY_REPEATED, "repeat device discovery warning."},
{ERR_DM_UNSUPPORTED_AUTH_TYPE, "auth type not supported."},
{ERR_DM_AUTH_BUSINESS_BUSY, "authentication service is busy."},
{ERR_DM_AUTH_OPEN_SESSION_FAILED, "open auth session failed."},
{ERR_DM_AUTH_PEER_REJECT, "remote device refused to authorization."},
{ERR_DM_AUTH_REJECT, "local device refused to authorization."},
{ERR_DM_AUTH_FAILED, "authentication failed."},
{ERR_DM_AUTH_NOT_START, "auth process not started."},
{ERR_DM_AUTH_MESSAGE_INCOMPLETE, "authentication message is incomplete."},
{ERR_DM_CREATE_GROUP_FAILED, "create group failed."},
};
std::string GetErrorString(int failedReason)
{
std::string errorMessage = "undefined error code.";
for (int32_t i = 0; i < sizeof(g_errorMessages); i++) {
if (failedReason == g_errorMessages[i].errCode) {
errorMessage = g_errorMessages[i].errMsg;
break;
}
}
return errorMessage;
}
} // namespace DistributedHardware
} // namespace OHOS