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 #ifndef NAPI_AUDIO_ERROR_H
16 #define NAPI_AUDIO_ERROR_H
17 
18 #include <map>
19 #include <string>
20 #include "napi/native_api.h"
21 #include "napi/native_common.h"
22 #include "napi/native_node_api.h"
23 #include "audio_errors.h"
24 
25 namespace OHOS {
26 namespace AudioStandard {
27 class NapiAudioError {
28 public:
29     static napi_status ThrowError(napi_env env, const char *napiMessage, int32_t napiCode);
30     static void ThrowError(napi_env env, int32_t code);
31     static void ThrowError(napi_env env, int32_t code, const std::string &errMessage);
32     static napi_value ThrowErrorAndReturn(napi_env env, int32_t errCode);
33     static napi_value ThrowErrorAndReturn(napi_env env, int32_t errCode, const std::string &errMessage);
34     static std::string GetMessageByCode(int32_t &code);
35 };
36 
37 const int32_t NAPI_ERROR_INVALID_PARAM = 6800101;
38 const int32_t NAPI_ERR_NO_PERMISSION = 201;
39 const int32_t NAPI_ERR_PERMISSION_DENIED = 202;
40 const int32_t NAPI_ERR_INPUT_INVALID = 401;
41 const int32_t NAPI_ERR_INVALID_PARAM = 6800101;
42 const int32_t NAPI_ERR_NO_MEMORY = 6800102;
43 const int32_t NAPI_ERR_ILLEGAL_STATE = 6800103;
44 const int32_t NAPI_ERR_UNSUPPORTED = 6800104;
45 const int32_t NAPI_ERR_TIMEOUT = 6800105;
46 const int32_t NAPI_ERR_STREAM_LIMIT = 6800201;
47 const int32_t NAPI_ERR_SYSTEM = 6800301;
48 
49 const std::string NAPI_ERROR_INVALID_PARAM_INFO = "input parameter value error";
50 const std::string NAPI_ERROR_PERMISSION_DENIED_INFO = "not system app";
51 const std::string NAPI_ERR_INPUT_INVALID_INFO = "input parameter type or number mismatch";
52 const std::string NAPI_ERR_INVALID_PARAM_INFO = "invalid parameter";
53 const std::string NAPI_ERR_NO_MEMORY_INFO = "allocate memory failed";
54 const std::string NAPI_ERR_ILLEGAL_STATE_INFO = "Operation not permit at current state";
55 const std::string NAPI_ERR_UNSUPPORTED_INFO = "unsupported option";
56 const std::string NAPI_ERR_TIMEOUT_INFO = "time out";
57 const std::string NAPI_ERR_STREAM_LIMIT_INFO = "stream number limited";
58 const std::string NAPI_ERR_SYSTEM_INFO = "system error";
59 const std::string NAPI_ERR_NO_PERMISSION_INFO = "permission denied";
60 } // namespace AudioStandard
61 } // namespace OHOS
62 #endif // NAPI_AUDIO_ERROR_H
63