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