diff --git a/frameworks/ets/ani/include/sts_throw_erro.h b/frameworks/ets/ani/include/sts_throw_erro.h index 6dd7a6e5c463a5d9b361cbcc43f64de8ad055969..eddfa6ab0968cc9a8ce492f27dc9a17980e23b76 100644 --- a/frameworks/ets/ani/include/sts_throw_erro.h +++ b/frameworks/ets/ani/include/sts_throw_erro.h @@ -25,83 +25,13 @@ namespace OHOS { namespace NotificationSts { using namespace OHOS::Notification; -static const std::unordered_map ERROR_CODE_TO_MESSAGE { - {ERROR_PERMISSION_DENIED, "Permission denied"}, - {ERROR_NOT_SYSTEM_APP, "The application isn't system application"}, - {ERROR_PARAM_INVALID, "Invalid parameter"}, - {ERROR_SYSTEM_CAP_ERROR, "SystemCapability not found"}, - {ERROR_INTERNAL_ERROR, "Internal error"}, - {ERROR_IPC_ERROR, "Marshalling or unmarshalling error"}, - {ERROR_SERVICE_CONNECT_ERROR, "Failed to connect to the service"}, - {ERROR_NOTIFICATION_CLOSED, "Notification disabled"}, - {ERROR_SLOT_CLOSED, "Notification slot disabled"}, - {ERROR_NOTIFICATION_UNREMOVABLE, "Notification deletion disabled"}, - {ERROR_NOTIFICATION_NOT_EXIST, "The notification does not exist"}, - {ERROR_USER_NOT_EXIST, "The user does not exist"}, - {ERROR_OVER_MAX_NUM_PER_SECOND, "The notification sending frequency reaches the upper limit"}, - {ERROR_DISTRIBUTED_OPERATION_FAILED, "Distributed operation failed"}, - {ERROR_READ_TEMPLATE_CONFIG_FAILED, "Failed to read the template configuration"}, - {ERROR_NO_MEMORY, "No memory space"}, - {ERROR_BUNDLE_NOT_FOUND, "The specified bundle name was not found"}, - {ERROR_NO_AGENT_SETTING, "There is no corresponding agent relationship configuration"}, - {ERROR_DIALOG_IS_POPPING, "Dialog is popping"}, - {ERROR_SETTING_WINDOW_EXIST, "The notification settings window is already displayed"}, - {ERROR_NO_PROFILE_TEMPLATE, "The do-not-disturb profile does not exist"}, - {ERROR_REPEAT_SET, "Repeat create or end"}, - {ERROR_NO_RIGHT, "No permission"}, - {ERROR_EXPIRED_NOTIFICATION, "Low update version"}, - {ERROR_NETWORK_UNREACHABLE, "Network unreachable"}, - {ERROR_REJECTED_WITH_DISABLE_NOTIFICATION, - "The application is not allowed to send notifications due to permission settings"}, - {ERROR_DISTRIBUTED_OPERATION_TIMEOUT, "Distributed operation timeout"}, -}; - -static const std::vector> ERRORS_CONVERT = { - {ERR_ANS_PERMISSION_DENIED, ERROR_PERMISSION_DENIED}, - {ERR_ANS_NON_SYSTEM_APP, ERROR_NOT_SYSTEM_APP}, - {ERR_ANS_NOT_SYSTEM_SERVICE, ERROR_NOT_SYSTEM_APP}, - {ERR_ANS_INVALID_PARAM, ERROR_PARAM_INVALID}, - {ERR_ANS_INVALID_UID, ERROR_PARAM_INVALID}, - {ERR_ANS_ICON_OVER_SIZE, ERROR_PARAM_INVALID}, - {ERR_ANS_PICTURE_OVER_SIZE, ERROR_PARAM_INVALID}, - {ERR_ANS_PUSH_CHECK_EXTRAINFO_INVALID, ERROR_PARAM_INVALID}, - {ERR_ANS_NO_MEMORY, ERROR_NO_MEMORY}, - {ERR_ANS_TASK_ERR, ERROR_INTERNAL_ERROR}, - {ERR_ANS_PARCELABLE_FAILED, ERROR_IPC_ERROR}, - {ERR_ANS_TRANSACT_FAILED, ERROR_IPC_ERROR}, - {ERR_ANS_REMOTE_DEAD, ERROR_IPC_ERROR}, - {ERR_ANS_SERVICE_NOT_READY, ERROR_SERVICE_CONNECT_ERROR}, - {ERR_ANS_SERVICE_NOT_CONNECTED, ERROR_SERVICE_CONNECT_ERROR}, - {ERR_ANS_NOT_ALLOWED, ERROR_NOTIFICATION_CLOSED}, - {ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_ENABLED, ERROR_SLOT_CLOSED}, - {ERR_ANS_NOTIFICATION_IS_UNREMOVABLE, ERROR_NOTIFICATION_UNREMOVABLE}, - {ERR_ANS_NOTIFICATION_NOT_EXISTS, ERROR_NOTIFICATION_NOT_EXIST}, - {ERR_ANS_GET_ACTIVE_USER_FAILED, ERROR_USER_NOT_EXIST}, - {ERR_ANS_INVALID_PID, ERROR_BUNDLE_NOT_FOUND}, - {ERR_ANS_INVALID_BUNDLE, ERROR_BUNDLE_NOT_FOUND}, - {ERR_ANS_OVER_MAX_ACTIVE_PERSECOND, ERROR_OVER_MAX_NUM_PER_SECOND}, - {ERR_ANS_OVER_MAX_UPDATE_PERSECOND, ERROR_OVER_MAX_NUM_PER_SECOND}, - {ERR_ANS_DISTRIBUTED_OPERATION_FAILED, ERROR_DISTRIBUTED_OPERATION_FAILED}, - {ERR_ANS_DISTRIBUTED_GET_INFO_FAILED, ERROR_DISTRIBUTED_OPERATION_FAILED}, - {ERR_ANS_PREFERENCES_NOTIFICATION_READ_TEMPLATE_CONFIG_FAILED, ERROR_READ_TEMPLATE_CONFIG_FAILED}, - {ERR_ANS_REPEAT_CREATE, ERROR_REPEAT_SET}, - {ERR_ANS_END_NOTIFICATION, ERROR_REPEAT_SET}, - {ERR_ANS_EXPIRED_NOTIFICATION, ERROR_EXPIRED_NOTIFICATION}, - {ERR_ANS_PUSH_CHECK_FAILED, ERROR_NO_RIGHT}, - {ERR_ANS_PUSH_CHECK_UNREGISTERED, ERROR_NO_RIGHT}, - {ERR_ANS_LOCAL_SUBSCRIBE_CHECK_FAILED, ERROR_NO_RIGHT}, - {ERR_ANS_PUSH_CHECK_NETWORK_UNREACHABLE, ERROR_NETWORK_UNREACHABLE}, - {ERR_ANS_NO_AGENT_SETTING, ERROR_NO_AGENT_SETTING}, - {ERR_ANS_DIALOG_IS_POPPING, ERROR_DIALOG_IS_POPPING}, - {ERR_ANS_NO_PROFILE_TEMPLATE, ERROR_NO_PROFILE_TEMPLATE}, - {ERR_ANS_REJECTED_WITH_DISABLE_NOTIFICATION, ERROR_REJECTED_WITH_DISABLE_NOTIFICATION}, - {ERR_ANS_OPERATION_TIMEOUT, ERROR_DISTRIBUTED_OPERATION_TIMEOUT}, -}; - int32_t GetExternalCode(uint32_t errCode); -std::string FindAnsErrMsg(const int32_t errCode); +inline std::string FindAnsErrMsg(const int32_t errCode) +{ + return GetAnsErrMessage(errCode); +} void ThrowError(ani_env *env, int32_t errCode, const std::string &errorMsg); diff --git a/frameworks/ets/ani/src/sts_throw_erro.cpp b/frameworks/ets/ani/src/sts_throw_erro.cpp index bf5c8b17f3ab914867b6e5ce5b5dae7f02746273..c89b86c6407b106777d9239486e9fced32b5e611 100644 --- a/frameworks/ets/ani/src/sts_throw_erro.cpp +++ b/frameworks/ets/ani/src/sts_throw_erro.cpp @@ -19,27 +19,24 @@ namespace NotificationSts { constexpr const char *BUSINESS_ERROR_CLASS = "L@ohos/base/BusinessError;"; constexpr const char *ERROR_CLASS_NAME = "Lescompat/Error;"; -std::string FindAnsErrMsg(const int32_t errCode) -{ - auto findMsg = ERROR_CODE_TO_MESSAGE.find(errCode); - if (findMsg == ERROR_CODE_TO_MESSAGE.end()) { - ANS_LOGE("FindAnsErrMsg Inner error."); - return "Inner error."; - } - return findMsg->second; -} - int32_t GetExternalCode(uint32_t errCode) { - for (const auto &errorConvert : ERRORS_CONVERT) { - if (static_cast(errCode) == errorConvert.second) { - return errCode; - } - if (errCode == errorConvert.first) { - return errorConvert.second; - } + int32_t externalCode = ERROR_INTERNAL_ERROR; + switch (errCode) { + case ERROR_PERMISSION_DENIED: + case ERROR_NOT_SYSTEM_APP: + case ERROR_PARAM_INVALID: + case ERROR_SYSTEM_CAP_ERROR: + case ERROR_INTERNAL_ERROR: + case ERROR_DIALOG_IS_POPPING: + case ERROR_NO_MEMORY: + externalCode = static_cast(errCode); + break; + default: + externalCode = ErrorToExternal(errCode); + break; } - return ERROR_INTERNAL_ERROR; + return externalCode; } void ThrowError(ani_env *env, ani_object err)