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