• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 
16 #ifndef ASSET_NAPI_ERROR_CODE_H
17 #define ASSET_NAPI_ERROR_CODE_H
18 
19 #include <unordered_map>
20 #include <stdint.h>
21 
22 #include "asset_type.h"
23 
24 namespace OHOS {
25 namespace Security {
26 namespace Asset {
27 
28 const std::unordered_map<int32_t, const char *> ERR_MSGS = {
29     { ASSET_SUCCESS, "The operation is successful." },
30     { ASSET_PERMISSION_DENIED, "The caller doesn't have the permission." },
31     { ASSET_INVALID_ARGUMENT, "The argument is invalid." },
32     { ASSET_UNSUPPORTED, "The capability is not supported." },
33     { ASSET_SERVICE_UNAVAILABLE, "The ASSET Service is unavailable." },
34     { ASSET_NOT_FOUND, "The queried Asset can not be found." },
35     { ASSET_DUPLICATED, "The Asset already exists." },
36     { ASSET_ACCESS_DENIED, "The access to Asset is denied." },
37     { ASSET_STATUS_MISMATCH, "The screen lock status mismatches." },
38     { ASSET_OUT_OF_MEMORY, "Insufficient memory." },
39     { ASSET_DATA_CORRUPTED, "The Asset is corrupted." },
40     { ASSET_DATABASE_ERROR, "The database operation is failed." },
41     { ASSET_CRYPTO_ERROR, "The cryptography operation is failed." },
42     { ASSET_IPC_ERROR, "IPC communication is failed." },
43     { ASSET_BMS_ERROR, "The operation of calling Bundle Manager Service is failed." },
44     { ASSET_ACCOUNT_ERROR, "The operation of calling OS Account Service is failed." },
45     { ASSET_ACCESS_TOKEN_ERROR, "The operation of calling Access Token Service is failed." },
46     { ASSET_FILE_OPERATION_ERROR, "The operation of file is failed." },
47     { ASSET_GET_SYSTEM_TIME_ERROR, "The operation of getting system time is failed." },
48     { ASSET_LIMIT_EXCEEDED, "The cache exceeds the limit." },
49 };
50 
GetErrorMessage(int32_t errCode)51 inline const char *GetErrorMessage(int32_t errCode)
52 {
53     auto iter = ERR_MSGS.find(errCode);
54     if (iter == ERR_MSGS.end()) {
55         return "";
56     }
57     return ERR_MSGS.at(errCode);
58 }
59 
60 } // Asset
61 } // Security
62 } // OHOS
63 
64 #endif // ASSET_NAPI_ERROR_CODE_H