• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 INTERFACES_KITS_NAPI_COMMON_UNI_ERROR_H
17 #define INTERFACES_KITS_NAPI_COMMON_UNI_ERROR_H
18 
19 #include <iosfwd>
20 
21 #include "node_api.h"
22 #include "js_native_api_types.h"
23 
24 namespace OHOS {
25 namespace DistributedFS {
26 constexpr int ERRNO_NOERR = 0;
27 
28 enum ELegacy {
29     ELEGACY_INVAL = 202,
30     ELEGACY_IO = 300,
31     ELEGACY_NOENT = 301,
32 };
33 
34 enum ErrCodeSystem {
35     ERR_CODE_SYSTEM_LEGACY,
36     ERR_CODE_SYSTEM_POSIX,
37 };
38 
39 class UniError {
40 public:
41     UniError();
42     explicit UniError(ELegacy eLegacy);
43     explicit UniError(int ePosix);
44     UniError(const UniError &) = default;
45     ~UniError() = default;
46 
47     UniError &operator = (const UniError &) = default;
48 
49     explicit operator bool() const;
50 
51     void SetErrno(ELegacy eLegacy);
52     void SetErrno(int ePosix);
53     int GetErrno(ErrCodeSystem cs);
54 
55     std::string GetDefaultErrstr();
56     napi_value GetNapiErr(napi_env env);
57     napi_value GetNapiErr(napi_env env, std::string errMsg);
58     void ThrowErr(napi_env env);
59     void ThrowErr(napi_env env, std::string errMsg);
60 
61 private:
62     int errno_ = ERRNO_NOERR;
63     ErrCodeSystem codingSystem_ = ERR_CODE_SYSTEM_POSIX;
64 };
65 } // namespace DistributedFS
66 } // namespace OHOS
67 #endif