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 ERR_FORM_EXTERNAL_ADD_FORM_TIME_OUT = 16501008, 47 }; 48 49 /** 50 * @class FormErrors 51 * FormErrors is used to access form error message. 52 */ 53 class FormErrors final : public DelayedRefSingleton<FormErrors> { 54 DECLARE_DELAYED_REF_SINGLETON(FormErrors) 55 public: 56 DISALLOW_COPY_AND_MOVE(FormErrors); 57 58 /** 59 * @brief Get the error message content. 60 * 61 * @param errCode Error code. 62 * @return Message content. 63 */ 64 std::string GetErrorMessage(int errCode); 65 66 /** 67 * @brief Get external error code by internal error code. 68 * 69 * @param internalErrorCode Internal error code. 70 * @return External error code. 71 */ 72 int32_t QueryExternalErrorCode(int32_t internalErrorCode); 73 74 /** 75 * @brief Get external error message by error code. 76 * 77 * @param internalErrorCode Internal error code. 78 * @param externalErrorCode External error code. 79 * @return External error message. 80 */ 81 std::string QueryExternalErrorMessage(int32_t internalErrorCode, int32_t externalErrorCode); 82 83 /** 84 * @brief Get external error message by external error code. 85 * 86 * @param externalErrorCode External error code. 87 * @return External error message. 88 */ 89 std::string GetErrorMsgByExternalErrorCode(int32_t externalErrorCode); 90 91 private: 92 /** 93 * @brief Init error message map object. 94 * 95 */ 96 void InitErrorMessageMap(); 97 98 private: 99 std::map<ErrCode, std::string> errorMessageMap_; 100 }; 101 } // namespace AppExecFwk 102 } // namespace OHOS 103 #endif // OHOS_FORM_FWK_FORM_ERRORS_H 104