1 /* 2 * Copyright (c) 2021-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 OHOS_FORM_FWK_FORM_ERRORS_H 17 #define OHOS_FORM_FWK_FORM_ERRORS_H 18 19 #include <cstring> 20 #include <map> 21 22 #include "errors.h" 23 #include "nocopyable.h" 24 #include "singleton.h" 25 26 namespace OHOS { 27 namespace AppExecFwk { 28 enum { 29 ERR_FORM_EXTERNAL_PERMISSION_DENIED = 201, 30 ERR_FORM_EXTERNAL_NOT_SYSTEM_APP = 202, 31 ERR_FORM_EXTERNAL_PARAM_INVALID = 401, 32 ERR_FORM_EXTERNAL_SYSTEMCAP_ERROR = 801, 33 ERR_FORM_EXTERNAL_KERNEL_ERROR = 16500001, 34 ERR_FORM_EXTERNAL_KERNEL_MALLOC_ERROR = 16500002, 35 ERR_FORM_EXTERNAL_IPC_ERROR = 16500050, 36 ERR_FORM_EXTERNAL_SERVICE_CONNECTION_ERROR = 16500060, 37 ERR_FORM_EXTERNAL_GET_INFO_FAILED = 16500100, 38 ERR_FORM_EXTERNAL_FUNCTIONAL_ERROR = 16501000, 39 ERR_FORM_EXTERNAL_FORM_ID_NOT_EXIST = 16501001, 40 ERR_FORM_EXTERNAL_FORM_NUM_EXCEEDS_UPPER_BOUND = 16501002, 41 ERR_FORM_EXTERNAL_OPERATION_FORM_NOT_SELF = 16501003, 42 ERR_FORM_EXTERNAL_ABILITY_NOT_INSTALLED = 16501004, 43 ERR_FORM_EXTERNAL_CONNECT_RENDER_FAILED = 16501005, 44 ERR_FORM_EXTERNAL_RENDER_DIED = 16501006, 45 ERR_FORM_EXTERNAL_FORM_NOT_TRUST = 16501007, 46 }; 47 48 /** 49 * @class FormErrors 50 * FormErrors is used to access form error message. 51 */ 52 class FormErrors final : public DelayedRefSingleton<FormErrors> { 53 DECLARE_DELAYED_REF_SINGLETON(FormErrors) 54 public: 55 DISALLOW_COPY_AND_MOVE(FormErrors); 56 57 /** 58 * @brief Get the error message content. 59 * 60 * @param errCode Error code. 61 * @return Message content. 62 */ 63 std::string GetErrorMessage(int errCode); 64 65 /** 66 * @brief Get external error code by internal error code. 67 * 68 * @param internalErrorCode Internal error code. 69 * @return External error code. 70 */ 71 int32_t QueryExternalErrorCode(int32_t internalErrorCode); 72 73 /** 74 * @brief Get external error message by error code. 75 * 76 * @param internalErrorCode Internal error code. 77 * @param externalErrorCode External error code. 78 * @return External error message. 79 */ 80 std::string QueryExternalErrorMessage(int32_t internalErrorCode, int32_t externalErrorCode); 81 82 /** 83 * @brief Get external error message by external error code. 84 * 85 * @param externalErrorCode External error code. 86 * @return External error message. 87 */ 88 std::string GetErrorMsgByExternalErrorCode(int32_t externalErrorCode); 89 90 private: 91 /** 92 * @brief Init error message map object. 93 * 94 */ 95 void InitErrorMessageMap(); 96 97 private: 98 std::map<ErrCode, std::string> errorMessageMap_; 99 }; 100 } // namespace AppExecFwk 101 } // namespace OHOS 102 #endif // OHOS_FORM_FWK_FORM_ERRORS_H 103