1/* 2 * Copyright (c) 2025 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 16import Constants from './constant'; 17import Result from './Result'; 18 19export class ResultMsg { 20 private static readonly STRING_OPEN_FILE_ERROR: string = 'Open file error.'; 21 private static readonly STRING_PARAMS_CHECK_ERROR: string = 'Params check error.'; 22 private static readonly STRING_CREATE_DECRYPT_ERROR: string = 'Create decrypt task error.'; 23 private static readonly STRING_PARSE_DLP_FILE_ERROR: string = 'Parse dlp file error.'; 24 private static readonly STRING_ERR_CODE_NETWORK_ERROR: string = 'Network invalid error.'; 25 private static readonly STRING_ERR_START_ABILITY_ERROR: string = 'Failed to invoke startAbility'; 26 private static readonly STRING_ERR_GET_ACCOUNT_ERROR: string = 'Failed to get account info'; 27 private static readonly STRING_ERR_NO_ACCOUNT_ERROR: string = 'No account error'; 28 private static readonly STRING_NO_AUTHENTICATED_ERROR: string = 'No authenticated'; 29 private static readonly STRING_ERR_JS_ACCOUNT_NOT_LOGIN_ERROR: string = 'Cloud account not login'; 30 private static readonly STRING_GET_BUNDLE_INFO_ERROR: string = 'GetBundleInfoForSelf error'; 31 private static readonly STRING_GET_LOCK_ASYNC_ERROR: string = 'Lock async error'; 32 private static readonly STRING_FILE_IS_DECRYPTING_ERROR: string = 'File is decrypting'; 33 private static readonly STRING_FILE_IS_ENCRYPTING_ERROR: string = 'File is encrypting'; 34 private static readonly STRING_NOT_AUTHORIZED_APP: string = 'Get AppId failed'; 35 private static readonly STRING_APP_INSIDE_ERROR: string = 'App inside error'; 36 private static readonly STRING_DEFAULT_ERROR: string = 'Default error'; 37 private static readonly STRING_JS_APP_NETWORK_INVALID_ERROR: string = 'Network invalid error'; 38 private static readonly STRING_SHARE_NO_SPACE_LEFT_ON_DEVICE: string = 'Share no space left on device'; 39 private static readonly STRING_NOT_DLP_FILE: string = 'Not dlp file'; 40 private static readonly STRING_GET_FILE_ASSET_ERROR: string = 'Get file asset error'; 41 private static readonly STRING_USER_STOP_DIALOG: string = 'User stop dialog'; 42 private static readonly STRING_USER_NO_PERMISSION: string = 'User no permission'; 43 private static readonly STRING_APP_PERMISSION_DENY: string = 'App permission deny'; 44 private static readonly STRING_OTHER_APP_OPEN_FILE: string = 'Other app is opening this file'; 45 46 private constructor() { 47 } 48 49 public static buildMsg<T>(code: number, msg?: string): Result<T> { 50 return { 51 errcode: code, 52 errmsg: msg 53 }; 54 } 55 56 public static buildResult<T>(code: number, msg?: string, obj?: T): Result<T> { 57 return { 58 errcode: code, 59 errmsg: msg, 60 result: obj 61 }; 62 } 63 64 public static buildSuccess<T>(obj?: T): Result<T> { 65 return ResultMsg.buildResult(Constants.ERR_CODE_SUCCESS, '', obj); 66 } 67 68 private static readonly errMsgMap: Map<number, string> = new Map([ 69 [Constants.ERR_CODE_OPEN_FILE_ERROR, ResultMsg.STRING_OPEN_FILE_ERROR], 70 [Constants.ERR_CODE_PARAMS_CHECK_ERROR, ResultMsg.STRING_PARAMS_CHECK_ERROR], 71 [Constants.ERR_CODE_CREATE_DECRYPT_TASK_ERROR, ResultMsg.STRING_CREATE_DECRYPT_ERROR], 72 [Constants.ERR_CODE_PARSE_DLP_FILE_ERROR, ResultMsg.STRING_PARSE_DLP_FILE_ERROR], 73 [Constants.ERR_CODE_NETWORK_ERROR, ResultMsg.STRING_ERR_CODE_NETWORK_ERROR], 74 [Constants.ERR_CODE_START_ABILITY_ERROR, ResultMsg.STRING_ERR_START_ABILITY_ERROR], 75 [Constants.ERR_JS_GET_ACCOUNT_ERROR, ResultMsg.STRING_ERR_GET_ACCOUNT_ERROR], 76 [Constants.ERR_JS_APP_NO_ACCOUNT_ERROR, ResultMsg.STRING_ERR_NO_ACCOUNT_ERROR], 77 [Constants.ERR_JS_APP_SYSTEM_IS_AUTHENTICATED, ResultMsg.STRING_NO_AUTHENTICATED_ERROR], 78 [Constants.ERR_JS_ACCOUNT_NOT_LOGIN, ResultMsg.STRING_ERR_JS_ACCOUNT_NOT_LOGIN_ERROR], 79 [Constants.ERR_CODE_GET_BUNDLE_INFO_ERROR, ResultMsg.STRING_GET_BUNDLE_INFO_ERROR], 80 [Constants.ERR_CODE_GET_LOCK_ASYNC_ERROR, ResultMsg.STRING_GET_LOCK_ASYNC_ERROR], 81 [Constants.ERR_CODE_FILE_IS_DECRYPTING_ERROR, ResultMsg.STRING_FILE_IS_DECRYPTING_ERROR], 82 [Constants.ERR_JS_APP_ENCRYPTION_REJECTED, ResultMsg.STRING_FILE_IS_ENCRYPTING_ERROR], 83 [Constants.ERR_JS_NOT_AUTHORIZED_APPLICATION, ResultMsg.STRING_NOT_AUTHORIZED_APP], 84 [Constants.ERR_JS_APP_INSIDE_ERROR, ResultMsg.STRING_APP_INSIDE_ERROR], 85 [Constants.ERR_JS_APP_NETWORK_INVALID, ResultMsg.STRING_JS_APP_NETWORK_INVALID_ERROR], 86 [Constants.SHARE_NO_SPACE_LEFT_ON_DEVICE, ResultMsg.STRING_SHARE_NO_SPACE_LEFT_ON_DEVICE], 87 [Constants.ERR_JS_NOT_DLP_FILE, ResultMsg.STRING_NOT_DLP_FILE], 88 [Constants.ERR_JS_APP_GET_FILE_ASSET_ERROR, ResultMsg.STRING_GET_FILE_ASSET_ERROR], 89 [Constants.ERR_CODE_USER_STOP_DIALOG, ResultMsg.STRING_USER_STOP_DIALOG], 90 [Constants.ERR_JS_APP_PERMISSION_DENY, ResultMsg.STRING_APP_PERMISSION_DENY], 91 [Constants.ERR_JS_OTHER_APP_OPEN_FILE, ResultMsg.STRING_OTHER_APP_OPEN_FILE], 92 ]); 93 94 public static getErrMsg<T>(errCode: number, errMsg?: string): Result<T> { 95 if (ResultMsg.errMsgMap.get(errCode)) { 96 return ResultMsg.buildMsg<T>(errCode, ResultMsg.errMsgMap.get(errCode)); 97 } 98 return ResultMsg.buildMsg<T>(errCode, errMsg ? errMsg : ResultMsg.STRING_DEFAULT_ERROR); 99 } 100}