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