• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 *PARAMETERERRORMESSAGE = "BusinessError 401: Parameter error.";
30 constexpr const char *PERMISSIONDENIEDMESSAGE = "BusinessError 201: Permission Denied.";
31 constexpr const char *EQUIPMENTERRORMESSAGE = "BusinessError 801: Equipment error.";
32 constexpr const char *PERMISSIONFAILEDMESSAGE = "BusinessError 202: Permission verification failed,"
33                                                 "application which is not a system application uses system API.";
34 enum ErrorThrowType : int32_t {
35     PERMISSION_ERROR = 201,
36     SYSTEM_APP_PERMISSION_ERROR = 202,
37     PARAMETER_ERROR = 401,
38     EQUIPMENT_ERROR = 801,
39     OPENFILE_FAILED = 13100001,
40     IMAGE_FORMAT_INCORRECT
41 };
42 struct JsErrorInfo {
43     int32_t code = 0;
44     std::string message;
45 };
46 
47 class JsError {
48 public:
49     static void ThrowError(napi_env env, int32_t errorCode, const std::string &errorMessage);
50     static JsErrorInfo ConvertErrorCode(ErrorCode wallpaperErrorCode);
51 };
52 } // namespace OHOS::WallpaperNAPI
53 
54 #endif // WALLPAPER_JS_ERROR_H
55