From d67a304b39504880b1a33353adc504cc6eff8e5d Mon Sep 17 00:00:00 2001 From: 18721213663 Date: Mon, 13 Mar 2023 15:55:26 +0800 Subject: [PATCH] fs_libn_add_throwerradddata Signed-off-by: 18721213663 --- utils/filemgmt_libn/include/n_error.h | 2 ++ utils/filemgmt_libn/src/n_error.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/utils/filemgmt_libn/include/n_error.h b/utils/filemgmt_libn/include/n_error.h index f7d0daa15..a86225a30 100644 --- a/utils/filemgmt_libn/include/n_error.h +++ b/utils/filemgmt_libn/include/n_error.h @@ -34,6 +34,7 @@ constexpr int FILEIO_SYS_CAP_TAG = 13900000; constexpr int USER_FILE_MANAGER_SYS_CAP_TAG = 14000000; constexpr int USER_FILE_SERVICE_SYS_CAP_TAG = 14300000; const std::string FILEIO_TAG_ERR_CODE = "code"; +const std::string FILEIO_TAG_ERR_DATA = "data"; enum ErrCodeSuffixOfFileIO { E_PERM = 1, @@ -294,6 +295,7 @@ public: napi_value GetNapiErr(napi_env env, int code); void ThrowErr(napi_env env); void ThrowErr(napi_env env, int code); + void ThrowErrAddData(napi_env env, int errCode, napi_value data); void ThrowErr(napi_env env, std::string errMsg); private: diff --git a/utils/filemgmt_libn/src/n_error.cpp b/utils/filemgmt_libn/src/n_error.cpp index 23b87cd91..adcaac3a9 100644 --- a/utils/filemgmt_libn/src/n_error.cpp +++ b/utils/filemgmt_libn/src/n_error.cpp @@ -126,6 +126,32 @@ void NError::ThrowErr(napi_env env, string errMsg) } } +void NError::ThrowErrAddData(napi_env env, int errCode, napi_value data) +{ + int32_t code; + string msg; + if (errCodeTable.find(errCode) != errCodeTable.end()) { + code = errCodeTable.at(errCode).first; + msg = errCodeTable.at(errCode).second; + } else { + code = errCodeTable.at(UNKROWN_ERR).first; + msg = errCodeTable.at(UNKROWN_ERR).second; + } + errno_ = code; + errMsg_ = msg; + napi_value businessError = GenerateBusinessError(env, code, msg); + napi_status status = napi_set_named_property(env, businessError, FILEIO_TAG_ERR_DATA.c_str(), data); + if (status != napi_ok) { + HILOGE("Failed to set data property on Error, error message is %{public}s", msg.c_str()); + return; + } + status = napi_throw(env, businessError); + if (status != napi_ok) { + HILOGE("Failed to throw a BusinessError, error message is %{public}s", msg.c_str()); + return; + } +} + void NError::ThrowErr(napi_env env) { napi_value tmp = nullptr; -- Gitee