1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef WALLPAPER_JS_ERROR_H 16 #define WALLPAPER_JS_ERROR_H 17 #include <string> 18 19 #include "hilog_wrapper.h" 20 #include "napi/native_api.h" 21 #include "napi/native_common.h" 22 #include "napi/native_node_api.h" 23 #include "wallpaper_common.h" 24 #include "wallpaper_manager_common_info.h" 25 26 namespace OHOS::WallpaperNAPI { 27 using namespace WallpaperMgrService; 28 29 constexpr const char *PARAMETER_ERROR_MESSAGE = "BusinessError 401: Parameter error."; 30 constexpr const char *PERMISSION_DENIED_MESSAGE = "BusinessError 201: Permission Denied."; 31 constexpr const char *EQUIPMENT_ERROR_MESSAGE = "BusinessError 801: Equipment error."; 32 constexpr const char *PERMISSION_FAILED_MESSAGE = "BusinessError 202: Permission verification failed," 33 "application which is not a system application uses system API."; 34 constexpr const char *PARAMETER_COUNT = "Mandatory parameters are left unspecified."; 35 constexpr const char *WALLPAPERTYPE_PARAMETER_TYPE = "The type must be WallpaperType, parameter range must be " 36 "WALLPAPER_LOCKSCREEN or WALLPAPER_SYSTEM."; 37 constexpr const char *FOLDSTATE_PARAMETER_TYPE = "The type must be FoldState, parameter range must be " 38 "NORMAL or UNFOLD_ONCE_STATE or UNFOLD_TWICE_STATE."; 39 constexpr const char *ROTATESTATE_PARAMETER_TYPE = "The type must be RotateState, parameter range must be " 40 "PORTRAIT or LANDSCAPE."; 41 constexpr const char *DYNAMIC_WALLPAPERTYPE_PARAMETER_TYPE = "The dynamic wallpaper must be .mp4 or conform to the " 42 "video format requirements."; 43 enum ErrorThrowType : int32_t { 44 PERMISSION_ERROR = 201, 45 SYSTEM_APP_PERMISSION_ERROR = 202, 46 PARAMETER_ERROR = 401, 47 EQUIPMENT_ERROR = 801, 48 OPENFILE_FAILED = 13100001, 49 IMAGE_FORMAT_INCORRECT 50 }; 51 struct JsErrorInfo { 52 int32_t code = 0; 53 std::string message; 54 }; 55 56 class JsError { 57 public: 58 static void ThrowError(napi_env env, int32_t errorCode, const std::string &errorMessage); 59 static JsErrorInfo ConvertErrorCode(ErrorCode wallpaperErrorCode); 60 }; 61 } // namespace OHOS::WallpaperNAPI 62 63 #endif // WALLPAPER_JS_ERROR_H 64