1 /* 2 * Copyright (c) 2022 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 #include "account_error_no.h" 17 18 namespace OHOS { AppAccountConvertOtherJSErrCode(int32_t errCode)19int32_t AppAccountConvertOtherJSErrCode(int32_t errCode) 20 { 21 switch (errCode) { 22 case ERR_APPACCOUNT_SERVICE_ACCOUNT_NOT_EXIST: 23 case ERR_APPACCOUNT_SERVICE_GET_ACCOUNT_INFO_BY_ID: 24 return ERR_JS_ACCOUNT_NOT_FOUND; 25 case ERR_APPACCOUNT_SERVICE_ADD_EXISTING_ACCOUNT: 26 return ERR_JS_ACCOUNT_ALREADY_EXIST; 27 case ERR_APPACCOUNT_SERVICE_ACCOUNT_MAX_SIZE: 28 return ERR_JS_ACCOUNT_NUMBER_REACH_LIMIT; 29 case ERR_APPACCOUNT_SUBSCRIBER_ALREADY_REGISTERED: 30 return ERR_JS_LISTENER_ALREADY_REGISTERED; 31 case ERR_APPACCOUNT_SERVICE_ASSOCIATED_DATA_OVER_SIZE: 32 return ERR_JS_CUSTOM_DATA_NUMBER_REACH_LIMIT; 33 case ERR_APPACCOUNT_SERVICE_ASSOCIATED_DATA_KEY_NOT_EXIST: 34 return ERR_JS_CUSTOM_DATA_NOT_FOUND; 35 case ERR_APPACCOUNT_SERVICE_ACCOUNT_CREDENTIAL_NOT_EXIST: 36 return ERR_JS_CREDENTIAL_NOT_EXIST; 37 case ERR_APPACCOUNT_KIT_NO_SPECIFIED_SUBSCRIBER_HAS_BEEN_REGISTERED: 38 return ERR_JS_LISTENER_NOT_REGISTERED; 39 case ERR_APPACCOUNT_SERVICE_OAUTH_AUTHENTICATOR_NOT_EXIST: 40 return ERR_JS_ACCOUNT_AUTHENTICATOR_NOT_EXIST; 41 case ERR_APPACCOUNT_SERVICE_OAUTH_BUSY: 42 return ERR_JS_ACCOUNT_SERVICE_BUSY; 43 case ERR_APPACCOUNT_SERVICE_OAUTH_LIST_MAX_SIZE: 44 return ERR_JS_AUTHORIZATION_LIST_TOO_LARGE; 45 case ERR_APPACCOUNT_SERVICE_OAUTH_SESSION_NOT_EXIST: 46 case ERR_APPACCOUNT_SERVICE_OAUTH_AUTHENTICATOR_CALLBACK_NOT_EXIST: 47 return ERR_JS_SESSION_NOT_EXIST; 48 case ERR_APPACCOUNT_SERVICE_OAUTH_TYPE_NOT_EXIST: 49 case ERR_APPACCOUNT_SERVICE_OAUTH_TOKEN_NOT_EXIST: 50 return ERR_JS_AUTH_TYPE_NOT_FOUND; 51 case ERR_APPACCOUNT_SERVICE_OAUTH_TOKEN_MAX_SIZE: 52 return ERR_JS_TOKEN_NUMBER_REACH_LIMIT; 53 default: 54 return ERR_JS_SYSTEM_SERVICE_EXCEPTION; 55 } 56 } 57 AppAccountConvertToJSErrCode(int32_t errCode)58int32_t AppAccountConvertToJSErrCode(int32_t errCode) 59 { 60 if (errCode == ERR_ACCOUNT_COMMON_PERMISSION_DENIED) { 61 return ERR_JS_PERMISSION_DENIED; 62 } else if (errCode == ERR_APPACCOUNT_SERVICE_GET_BUNDLE_NAME || 63 errCode == ERR_APPACCOUNT_SERVICE_GET_BUNDLE_INFO || 64 errCode == ERR_APPACCOUNT_SERVICE_DISABLE_APP_ACCESS_NOT_EXISTED) { 65 return ERR_JS_APPLICATION_NOT_EXIST; 66 } else if (errCode == ERR_APPACCOUNT_SERVICE_OAUTH_SERVICE_EXCEPTION) { 67 return ERR_JS_ACCOUNT_AUTHENTICATOR_SERVICE_EXCEPTION; 68 } else { 69 return AppAccountConvertOtherJSErrCode(errCode); 70 } 71 } 72 OsAccountConvertToJSErrCode(int32_t errCode)73int32_t OsAccountConvertToJSErrCode(int32_t errCode) 74 { 75 if (errCode == ERR_ACCOUNT_COMMON_INVALID_PARAMETER) { 76 return ERR_JS_INVALID_PARAMETER; 77 } 78 switch (errCode) { 79 case ERR_ACCOUNT_COMMON_ACCOUNT_NOT_EXIST_ERROR: 80 return ERR_JS_ACCOUNT_NOT_FOUND; 81 case ERR_OSACCOUNT_SERVICE_INNER_DOMAIN_ALREADY_BIND_ERROR: 82 return ERR_JS_ACCOUNT_ALREADY_EXIST; 83 case ERR_OSACCOUNT_SERVICE_INNER_ACCOUNT_ALREADY_ACTIVE_ERROR: 84 return ERR_JS_ACCOUNT_ALREADY_ACTIVATED; 85 case ERR_OSACCOUNT_SERVICE_CONTROL_MAX_CAN_CREATE_ERROR: 86 return ERR_JS_ACCOUNT_NUMBER_REACH_LIMIT; 87 case ERR_OSACCOUNT_SERVICE_MANAGER_NOT_ENABLE_MULTI_ERROR: 88 return ERR_JS_MULTI_USER_NOT_SUPPORT; 89 case ERR_OSACCOUNT_SERVICE_MANAGER_CREATE_OSACCOUNT_TYPE_ERROR: 90 return ERR_JS_ACCOUNT_TYPE_NOT_SUPPORT; 91 case ERR_OSACCOUNT_SERVICE_MANAGER_ID_ERROR: 92 case ERR_OSACCOUNT_SERVICE_CONTROL_CANNOT_DELETE_ID_ERROR: 93 case ERR_OSACCOUNT_SERVICE_CONTROL_ID_CANNOT_CREATE_ERROR: 94 return ERR_JS_ACCOUNT_RESTRICTED; 95 case ERR_OSACCOUNT_KIT_NO_SPECIFIED_SUBSCRIBER_HAS_BEEN_REGISTERED: 96 return ERR_JS_LISTENER_NOT_REGISTERED; 97 case ERR_ACCOUNT_COMMON_PERMISSION_DENIED: 98 return ERR_JS_PERMISSION_DENIED; 99 default: 100 return ERR_JS_SYSTEM_SERVICE_EXCEPTION; 101 } 102 } 103 DomainAccountConvertToJSErrCode(int32_t errCode)104static int32_t DomainAccountConvertToJSErrCode(int32_t errCode) 105 { 106 switch (errCode) { 107 case ERR_DOMAIN_ACCOUNT_SERVICE_PLUGIN_ALREADY_EXIST: 108 return ERR_JS_DOMAIN_PLUGIN_ALREADY_REGISTERED; 109 case ERR_DOMAIN_ACCOUNT_SERVICE_NOT_DOMAIN_ACCOUNT: 110 return ERR_JS_ACCOUNT_NOT_FOUND; 111 case ERR_DOMAIN_ACCOUNT_SERVICE_PLUGIN_NOT_EXIST: 112 return ERR_JS_CAPABILITY_NOT_SUPPORTED; 113 default: 114 return ERR_JS_SYSTEM_SERVICE_EXCEPTION; 115 } 116 } 117 IsAppAccountKitError(int32_t errCode)118static bool IsAppAccountKitError(int32_t errCode) 119 { 120 return (errCode >= ERR_APPACCOUNT_KIT_GET_APP_ACCOUNT_SERVICE && 121 errCode <= ERR_APPACCOUNT_KIT_READ_PARCELABLE_VECTOR_ACCOUNT_INFO); 122 } 123 IsAppAccountServiceError(int32_t errCode)124static bool IsAppAccountServiceError(int32_t errCode) 125 { 126 return (errCode >= ERR_APPACCOUNT_SERVICE_ACCOUNT_NOT_EXIST && errCode <= ERR_APPACCOUNT_SERVICE_OTHER); 127 } 128 IsOsAccountKitError(int32_t errCode)129static bool IsOsAccountKitError(int32_t errCode) 130 { 131 return (errCode >= ERR_OSACCOUNT_KIT_CREATE_OS_ACCOUNT_FOR_DOMAIN_ERROR && 132 errCode <= ERR_OSACCOUNT_KIT_NO_SPECIFIED_SUBSCRIBER_HAS_BEEN_REGISTERED); 133 } 134 IsOsAccountServiceError(int32_t errCode)135static bool IsOsAccountServiceError(int32_t errCode) 136 { 137 return (errCode >= ERR_OSACCOUNT_SERVICE_MANAGER_QUERY_DISTRIBUTE_DATA_ERROR) && 138 (errCode <= ERR_OSACCOUNT_SERVICE_STORAGE_PREPARE_ADD_USER_FAILED); 139 } 140 IsDomainAccountServiceError(int32_t errCode)141static bool IsDomainAccountServiceError(int32_t errCode) 142 { 143 return (errCode >= ERR_DOMAIN_ACCOUNT_SERVICE_PLUGIN_ALREADY_EXIST) && 144 (errCode <= ERR_DOMAIN_ACCOUNT_SERVICE_ERR_CODE_LIMIT); 145 } 146 ConvertToJSErrCode(int32_t nativeErrCode)147int32_t ConvertToJSErrCode(int32_t nativeErrCode) 148 { 149 if (nativeErrCode == ERR_OK) { 150 return ERR_JS_SUCCESS; 151 } 152 if (nativeErrCode == ERR_ACCOUNT_COMMON_NOT_SYSTEM_APP_ERROR) { 153 return ERR_JS_IS_NOT_SYSTEM_APP; 154 } 155 if (nativeErrCode == ERR_ACCOUNT_COMMON_INVALID_PARAMETER) { 156 return ERR_JS_INVALID_PARAMETER; 157 } 158 if (nativeErrCode == ERR_ACCOUNT_COMMON_ACCOUNT_NOT_EXIST_ERROR) { 159 return ERR_JS_ACCOUNT_NOT_FOUND; 160 } 161 if (IsAppAccountKitError(nativeErrCode) || IsAppAccountServiceError(nativeErrCode)) { 162 return AppAccountConvertToJSErrCode(nativeErrCode); 163 } else if (IsOsAccountKitError(nativeErrCode) || IsOsAccountServiceError(nativeErrCode)) { 164 return OsAccountConvertToJSErrCode(nativeErrCode); 165 } else if (IsDomainAccountServiceError(nativeErrCode)) { 166 return DomainAccountConvertToJSErrCode(nativeErrCode); 167 } else if (nativeErrCode == ERR_ACCOUNT_COMMON_PERMISSION_DENIED) { 168 return ERR_JS_PERMISSION_DENIED; 169 } else { 170 return ERR_JS_SYSTEM_SERVICE_EXCEPTION; 171 } 172 } 173 } // namespace OHOS