diff --git a/frameworks/js/napi/inner/napi_common/napi_common_ability.cpp b/frameworks/js/napi/inner/napi_common/napi_common_ability.cpp index ebc8dc23af..9543eab98a 100644 --- a/frameworks/js/napi/inner/napi_common/napi_common_ability.cpp +++ b/frameworks/js/napi/inner/napi_common/napi_common_ability.cpp @@ -5427,13 +5427,16 @@ NativeValue* JsNapiCommon::JsGetDisplayOrientation( } *value = obj->ability_->GetDisplayOrientation(); }; - auto complete = [obj = this, value = errorVal] - (NativeEngine &engine, AsyncTask &task, int32_t status) { - if (*value == NAPI_ERR_NO_ERROR) { + auto complete = [errorVal] (NativeEngine &engine, AsyncTask &task, int32_t status) { + if (*errorVal == NAPI_ERR_ACE_ABILITY) { task.Reject(engine, CreateJsError(engine, NAPI_ERR_ACE_ABILITY, "ability is nullptr")); + } else if (*errorVal == NAPI_ERR_ABILITY_TYPE_INVALID) { + task.Reject(engine, CreateJsError(engine, NAPI_ERR_ABILITY_TYPE_INVALID, "ability type is invalid.")); + } else if (*errorVal == NAPI_ERR_NO_WINDOW) { + task.Reject(engine, CreateJsError(engine, NAPI_ERR_NO_WINDOW, "window is nullptr")); + } else { + task.Resolve(engine, CreateJsValue(engine, *errorVal)); } - - task.Resolve(engine, CreateJsValue(engine, *value)); }; auto callback = info.argc == ARGS_ZERO ? nullptr : info.argv[PARAM0]; diff --git a/frameworks/js/napi/inner/napi_common/napi_common_error.h b/frameworks/js/napi/inner/napi_common/napi_common_error.h index 7e60cc8f89..2f7da39fc1 100644 --- a/frameworks/js/napi/inner/napi_common/napi_common_error.h +++ b/frameworks/js/napi/inner/napi_common/napi_common_error.h @@ -22,6 +22,7 @@ namespace OHOS { namespace AppExecFwk { #define NAPI_ERR_NO_ERROR 0 +#define NAPI_ERR_NO_WINDOW (-1) #define NAPI_ERR_NO_PERMISSION (-100) #define NAPI_ERR_INNER_DATA (-101) // Internal data error, data allocation fail #define NAPI_ERR_ACE_ABILITY (-102) // Failed to acquire ability object diff --git a/frameworks/native/ability/native/ability.cpp b/frameworks/native/ability/native/ability.cpp index 059f63ffff..05097fbb39 100644 --- a/frameworks/native/ability/native/ability.cpp +++ b/frameworks/native/ability/native/ability.cpp @@ -2089,13 +2089,13 @@ int Ability::GetDisplayOrientation() HILOG_DEBUG("%{public}s called.", __func__); if (abilityWindow_ == nullptr) { HILOG_ERROR("Ability::GetDisplayOrientation error. abilityWindow_ == nullptr."); - return 0; + return -1; } HILOG_DEBUG("FA mode"); auto window = abilityWindow_->GetWindow(); if (window == nullptr) { HILOG_ERROR("window is nullptr."); - return 0; + return -1; } auto orientation = window->GetRequestedOrientation(); if (orientation == Rosen::Orientation::HORIZONTAL) {