diff --git a/interfaces/kits/napi/include/native_distributedhardwarefwk_js.h b/interfaces/kits/napi/include/native_distributedhardwarefwk_js.h index 6f500540cc52526fb795b50aa9b77cfa979a902c..bf6a0052625904e970b9e7d69048373e395c5d97 100644 --- a/interfaces/kits/napi/include/native_distributedhardwarefwk_js.h +++ b/interfaces/kits/napi/include/native_distributedhardwarefwk_js.h @@ -43,6 +43,7 @@ public: const int32_t destLen); static void JsObjectToInt(const napi_env &env, const napi_value &object, const std::string &fieldStr, int32_t &fieldRef); + static napi_value CreateBusinessErr(napi_env env, int32_t errCode); private: static bool IsSystemApp(); diff --git a/interfaces/kits/napi/src/native_distributedhardwarefwk_js.cpp b/interfaces/kits/napi/src/native_distributedhardwarefwk_js.cpp index dad90c49b409e1891ba8556010b11f1f245cb474..41e892ab84d82d91e3978588d1dc4b76d681ca1b 100644 --- a/interfaces/kits/napi/src/native_distributedhardwarefwk_js.cpp +++ b/interfaces/kits/napi/src/native_distributedhardwarefwk_js.cpp @@ -120,10 +120,30 @@ bool DistributedHardwareManager::IsSystemApp() return OHOS::Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(tokenId); } +napi_value DistributedHardwareManager::CreateBusinessErr(napi_env env, int32_t errCode) +{ + napi_value error = nullptr; + switch (static_cast(errCode)) { + case ERR_NOT_SYSTEM_APP: + napi_throw_error(env, std::to_string(errCode).c_str(), ERR_MESSAGE_NOT_SYSTEM_APP.c_str()); + break; + case ERR_NO_PERMISSION: + napi_throw_error(env, std::to_string(errCode).c_str(), ERR_MESSAGE_NO_PERMISSION.c_str()); + break; + case ERR_INVALID_PARAMS: + napi_throw_error(env, std::to_string(errCode).c_str(), ERR_MESSAGE_INVALID_PARAMS.c_str()); + break; + default: + break; + } + return error; +} + napi_value DistributedHardwareManager::PauseDistributedHardware(napi_env env, napi_callback_info info) { DHLOGI("PauseDistributedHardware in"); if (!IsSystemApp()) { + CreateBusinessErr(env, ERR_NOT_SYSTEM_APP); return nullptr; } napi_value result = nullptr; @@ -176,6 +196,7 @@ napi_value DistributedHardwareManager::ResumeDistributedHardware(napi_env env, n { DHLOGI("ResumeDistributedHardware in"); if (!IsSystemApp()) { + CreateBusinessErr(env, ERR_NOT_SYSTEM_APP); return nullptr; } napi_value result = nullptr; @@ -228,6 +249,7 @@ napi_value DistributedHardwareManager::StopDistributedHardware(napi_env env, nap { DHLOGI("StopDistributedHardware in"); if (!IsSystemApp()) { + CreateBusinessErr(env, ERR_NOT_SYSTEM_APP); return nullptr; } napi_value result = nullptr;