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