diff --git a/zh-cn/application-dev/reference/apis/js-apis-inputmethod-extension-context.md b/zh-cn/application-dev/reference/apis/js-apis-inputmethod-extension-context.md index 1c9e18fee0ba6ad6597d1337435f6b444122fc95..916f9c9c04cd63f611621bd651c71217e35e03f4 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-inputmethod-extension-context.md +++ b/zh-cn/application-dev/reference/apis/js-apis-inputmethod-extension-context.md @@ -43,7 +43,7 @@ destroy(callback: AsyncCallback\): void **示例:** ```ts -this.context.destroy((err: Error) => { +this.context.destroy((err: BusinessError) => { if(err) { console.log('Failed to destroy context.'); return; @@ -71,7 +71,7 @@ destroy(): Promise\; ```ts this.context.destroy().then(() => { console.log('Succeed in destroying context.'); -}).catch((err: Error)=>{ +}).catch((err: BusinessError)=>{ console.log('Failed to destroy context.'); }); ``` diff --git a/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md b/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md index eed9555026cfafc2562956654d25d4609339e324..5c0d33c0f793333a18140e31499c0d9c829d874e 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md +++ b/zh-cn/application-dev/reference/apis/js-apis-inputmethod.md @@ -128,7 +128,7 @@ switchInputMethod(target: InputMethodProperty, callback: AsyncCallback<boolea ```ts let currentIme = inputMethod.getCurrentInputMethod(); try{ - inputMethod.switchInputMethod(currentIme, (err: Error, result: boolean) => { + inputMethod.switchInputMethod(currentIme, (err: BusinessError, result: boolean) => { if (err) { console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`); return; @@ -184,7 +184,7 @@ try { } else { console.error('Failed to switchInputMethod.'); } - }).catch((err: Error) => { + }).catch((err: BusinessError) => { console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`); }) } catch (err) { @@ -257,7 +257,7 @@ try { icon: "", iconId: 0, extra: extra - }, (err: Error, result: boolean) => { + }, (err: BusinessError, result: boolean) => { if (err) { console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`); return; @@ -329,7 +329,7 @@ try { } else { console.error('Failed to switchCurrentInputMethodSubtype.'); } - }).catch((err: Error) => { + }).catch((err: BusinessError) => { console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`); }) } catch(err) { @@ -390,7 +390,7 @@ switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inp let currentIme = inputMethod.getCurrentInputMethod(); let imSubType = inputMethod.getCurrentInputMethodSubtype(); try { - inputMethod.switchCurrentInputMethodAndSubtype(currentIme, imSubType, (err: Error, result: boolean) => { + inputMethod.switchCurrentInputMethodAndSubtype(currentIme, imSubType, (err: BusinessError, result: boolean) => { if (err) { console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`); return; @@ -450,7 +450,7 @@ try { } else { console.error('Failed to switchCurrentInputMethodAndSubtype.'); } - }).catch((err: Error) => { + }).catch((err: BusinessError) => { console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`); }) } catch(err) { @@ -704,7 +704,7 @@ try { enterKeyType: 1 } }; - inputMethodController.attach(true, textConfig, (err: Error) => { + inputMethodController.attach(true, textConfig, (err: BusinessError) => { if (err) { console.error(`Failed to attach: ${JSON.stringify(err)}`); return; @@ -762,7 +762,7 @@ try { }; inputMethodController.attach(true, textConfig).then(() => { console.log('Succeeded in attaching inputMethod.'); - }).catch((err: Error) => { + }).catch((err: BusinessError) => { console.error(`Failed to attach: ${JSON.stringify(err)}`); }) } catch(err) { @@ -801,7 +801,7 @@ showTextInput(callback: AsyncCallback<void>): void **示例:** ```ts -inputMethodController.showTextInput((err: Error) => { +inputMethodController.showTextInput((err: BusinessError) => { if (err) { console.error(`Failed to showTextInput: ${JSON.stringify(err)}`); return; @@ -843,7 +843,7 @@ showTextInput(): Promise<void> ```ts inputMethodController.showTextInput().then(() => { console.log('Succeeded in showing text input.'); -}).catch((err: Error) => { +}).catch((err: BusinessError) => { console.error(`Failed to showTextInput: ${JSON.stringify(err)}`); }); ``` @@ -881,7 +881,7 @@ hideTextInput(callback: AsyncCallback<void>): void **示例:** ```ts -inputMethodController.hideTextInput((err: Error) => { +inputMethodController.hideTextInput((err: BusinessError) => { if (err) { console.error(`Failed to hideTextInput: ${JSON.stringify(err)}`); return; @@ -925,7 +925,7 @@ hideTextInput(): Promise<void> ```ts inputMethodController.hideTextInput().then(() => { console.log('Succeeded in hiding inputMethod.'); -}).catch((err: Error) => { +}).catch((err: BusinessError) => { console.error(`Failed to hideTextInput: ${JSON.stringify(err)}`); }) ``` @@ -956,7 +956,7 @@ detach(callback: AsyncCallback<void>): void **示例:** ```ts -inputMethodController.detach((err: Error) => { +inputMethodController.detach((err: BusinessError) => { if (err) { console.error(`Failed to detach: ${JSON.stringify(err)}`); return; @@ -993,7 +993,7 @@ detach(): Promise<void> ```ts inputMethodController.detach().then(() => { console.log('Succeeded in detaching inputMethod.'); -}).catch((err: Error) => { +}).catch((err: BusinessError) => { console.error(`Failed to detach: ${JSON.stringify(err)}`); }); ``` @@ -1032,7 +1032,7 @@ setCallingWindow(windowId: number, callback: AsyncCallback<void>): void ```ts try { let windowId: number = 2000; - inputMethodController.setCallingWindow(windowId, (err: Error) => { + inputMethodController.setCallingWindow(windowId, (err: BusinessError) => { if (err) { console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`); return; @@ -1085,7 +1085,7 @@ try { let windowId: number = 2000; inputMethodController.setCallingWindow(windowId).then(() => { console.log('Succeeded in setting callingWindow.'); - }).catch((err: Error) => { + }).catch((err: BusinessError) => { console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`); }) } catch(err) { @@ -1123,7 +1123,7 @@ updateCursor(cursorInfo: CursorInfo, callback: AsyncCallback<void>): void ```ts try { let cursorInfo: inputMethod.CursorInfo = { left: 0, top: 0, width: 600, height: 800 }; - inputMethodController.updateCursor(cursorInfo, (err: Error) => { + inputMethodController.updateCursor(cursorInfo, (err: BusinessError) => { if (err) { console.error(`Failed to updateCursor: ${JSON.stringify(err)}`); return; @@ -1172,7 +1172,7 @@ try { let cursorInfo: inputMethod.CursorInfo = { left: 0, top: 0, width: 600, height: 800 }; inputMethodController.updateCursor(cursorInfo).then(() => { console.log('Succeeded in updating cursorInfo.'); - }).catch((err: Error) => { + }).catch((err: BusinessError) => { console.error(`Failed to updateCursor: ${JSON.stringify(err)}`); }) } catch(err) { @@ -1211,7 +1211,7 @@ changeSelection(text: string, start: number, end: number, callback: AsyncCallbac ```ts try { - inputMethodController.changeSelection('text', 0, 5, (err: Error) => { + inputMethodController.changeSelection('text', 0, 5, (err: BusinessError) => { if (err) { console.error(`Failed to changeSelection: ${JSON.stringify(err)}`); return; @@ -1261,7 +1261,7 @@ changeSelection(text: string, start: number, end: number): Promise<void> try { inputMethodController.changeSelection('test', 0, 5).then(() => { console.log('Succeeded in changing selection.'); - }).catch((err: Error) => { + }).catch((err: BusinessError) => { console.error(`Failed to changeSelection: ${JSON.stringify(err)}`); }) } catch(err) { @@ -1299,7 +1299,7 @@ updateAttribute(attribute: InputAttribute, callback: AsyncCallback<void>): ```ts try { let inputAttribute: inputMethod.InputAttribute = { textInputType: 0, enterKeyType: 1 }; - inputMethodController.updateAttribute(inputAttribute, (err: Error) => { + inputMethodController.updateAttribute(inputAttribute, (err: BusinessError) => { if (err) { console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`); return; @@ -1348,7 +1348,7 @@ try { let inputAttribute: inputMethod.InputAttribute = { textInputType: 0, enterKeyType: 1 }; inputMethodController.updateAttribute(inputAttribute).then(() => { console.log('Succeeded in updating attribute.'); - }).catch((err: Error) => { + }).catch((err: BusinessError) => { console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`); }) } catch(err) { @@ -1387,7 +1387,7 @@ stopInputSession(callback: AsyncCallback<boolean>): void ```ts try { - inputMethodController.stopInputSession((err: Error, result: boolean) => { + inputMethodController.stopInputSession((err: BusinessError, result: boolean) => { if (err) { console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`); return; @@ -1440,7 +1440,7 @@ try { } else { console.error('Failed to stopInputSession.'); } - }).catch((err: Error) => { + }).catch((err: BusinessError) => { console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`); }) } catch(err) { @@ -1480,7 +1480,7 @@ showSoftKeyboard(callback: AsyncCallback<void>): void **示例:** ```ts -inputMethodController.showSoftKeyboard((err: Error) => { +inputMethodController.showSoftKeyboard((err: BusinessError) => { if (!err) { console.log('Succeeded in showing softKeyboard.'); } else { @@ -1523,7 +1523,7 @@ showSoftKeyboard(): Promise<void> ```ts inputMethodController.showSoftKeyboard().then(() => { console.log('Succeeded in showing softKeyboard.'); -}).catch((err: Error) => { +}).catch((err: BusinessError) => { console.error(`Failed to show softKeyboard: ${JSON.stringify(err)}`); }); ``` @@ -1560,7 +1560,7 @@ hideSoftKeyboard(callback: AsyncCallback<void>): void **示例:** ```ts -inputMethodController.hideSoftKeyboard((err: Error) => { +inputMethodController.hideSoftKeyboard((err: BusinessError) => { if (!err) { console.log('Succeeded in hiding softKeyboard.'); } else { @@ -1603,7 +1603,7 @@ hideSoftKeyboard(): Promise<void> ```ts inputMethodController.hideSoftKeyboard().then(() => { console.log('Succeeded in hiding softKeyboard.'); -}).catch((err: Error) => { +}).catch((err: BusinessError) => { console.error(`Failed to hide softKeyboard: ${JSON.stringify(err)}`); }); ``` @@ -1631,7 +1631,7 @@ stopInput(callback: AsyncCallback<boolean>): void **示例:** ```ts -inputMethodController.stopInput((err: Error, result: boolean) => { +inputMethodController.stopInput((err: BusinessError, result: boolean) => { if (err) { console.error(`Failed to stopInput: ${JSON.stringify(err)}`); return; @@ -1673,7 +1673,7 @@ inputMethodController.stopInput().then((result: boolean) => { } else { console.error('Failed to stopInput.'); } -}).catch((err: Error) => { +}).catch((err: BusinessError) => { console.error(`Failed to stopInput: ${JSON.stringify(err)}`); }) ``` @@ -2577,7 +2577,7 @@ let inputMethodProperty: inputMethod.InputMethodProperty = { id: 'propertyId', } try { - inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err: Error, data: Array) => { + inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err: BusinessError, data: Array) => { if (err) { console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`); return; @@ -2665,7 +2665,7 @@ listCurrentInputMethodSubtype(callback: AsyncCallback<Array<InputMethodSub ```ts try { - inputMethodSetting.listCurrentInputMethodSubtype((err: Error, data: Array) => { + inputMethodSetting.listCurrentInputMethodSubtype((err: BusinessError, data: Array) => { if (err) { console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`); return; @@ -2748,7 +2748,7 @@ getInputMethods(enable: boolean, callback: AsyncCallback<Array<InputMethod ```ts try { - inputMethodSetting.getInputMethods(true, (err: Error, data: Array) => { + inputMethodSetting.getInputMethods(true, (err: BusinessError, data: Array) => { if (err) { console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`); return; @@ -2835,7 +2835,7 @@ showOptionalInputMethods(callback: AsyncCallback<boolean>): void ```ts try { - inputMethodSetting.showOptionalInputMethods((err: Error, data: boolean) => { + inputMethodSetting.showOptionalInputMethods((err: BusinessError, data: boolean) => { if (err) { console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`); return; @@ -2900,7 +2900,7 @@ listInputMethod(callback: AsyncCallback<Array<InputMethodProperty>>) **示例:** ```ts -inputMethodSetting.listInputMethod((err: Error, data: Array) => { +inputMethodSetting.listInputMethod((err: BusinessError, data: Array) => { if (err) { console.error(`Failed to listInputMethod: ${JSON.stringify(err)}`); return; @@ -2958,7 +2958,7 @@ displayOptionalInputMethod(callback: AsyncCallback<void>): void **示例:** ```ts -inputMethodSetting.displayOptionalInputMethod((err: Error) => { +inputMethodSetting.displayOptionalInputMethod((err: BusinessError) => { if (err) { console.error(`Failed to displayOptionalInputMethod: ${JSON.stringify(err)}`); return; diff --git a/zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md b/zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md index b45703720f190c6163b986c2dfbc013361a7ea57..c16af7541c317beb256c868ddcb1543be256fed6 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md +++ b/zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md @@ -512,7 +512,7 @@ let panelInfo: inputMethodEngine.PanelInfo = { } try { inputMethodEngine.getInputMethodAbility() - .createPanel(this.context, panelInfo, (err: Error, panel: inputMethodEngine.Panel) => { + .createPanel(this.context, panelInfo, (err: BusinessError, panel: inputMethodEngine.Panel) => { if (err) { console.error(`Failed to createPanel: ${JSON.stringify(err)}`); return; @@ -560,7 +560,7 @@ let panelInfo: inputMethodEngine.PanelInfo = { inputMethodEngine.getInputMethodAbility().createPanel(this.context, panelInfo) .then((panel: inputMethodEngine.Panel) => { console.log('Succeed in creating panel.'); - }).catch((err: Error) => { + }).catch((err: BusinessError) => { console.error(`Failed to create panel: ${JSON.stringify(err)}`); }) ``` @@ -590,7 +590,7 @@ let panelInfo: inputMethodEngine.PanelInfo = { let inputPanel: inputMethodEngine.Panel | undefined = undefined; try { inputMethodEngine.getInputMethodAbility() - .createPanel(this.context, panelInfo, (err: Error, panel: inputMethodEngine.Panel) => { + .createPanel(this.context, panelInfo, (err: BusinessError, panel: inputMethodEngine.Panel) => { if (err) { console.error(`Failed to create panel: ${JSON.stringify(err)}`); return; @@ -603,7 +603,7 @@ try { } try { if (inputPanel) { - inputMethodEngine.getInputMethodAbility().destroyPanel(inputPanel, (err: Error) => { + inputMethodEngine.getInputMethodAbility().destroyPanel(inputPanel, (err: BusinessError) => { if (err !== undefined) { console.error(`Failed to destroy panel: ${JSON.stringify(err)}`); return; @@ -645,7 +645,7 @@ let panelInfo: inputMethodEngine.PanelInfo = { let inputPanel: inputMethodEngine.Panel | undefined = undefined; try { inputMethodEngine.getInputMethodAbility() - .createPanel(this.context, panelInfo, (err: Error, panel: inputMethodEngine.Panel) => { + .createPanel(this.context, panelInfo, (err: BusinessError, panel: inputMethodEngine.Panel) => { if (err) { console.error(`Failed to create panel: ${JSON.stringify(err)}`); return; @@ -661,7 +661,7 @@ try { if (inputPanel) { inputMethodEngine.getInputMethodAbility().destroyPanel(inputPanel).then(() => { console.log('Succeed in destroying panel.'); - }).catch((err: Error) => { + }).catch((err: BusinessError) => { console.error(`Failed to destroy panel: ${JSON.stringify(err)}`); }); } @@ -996,7 +996,7 @@ setUiContent(path: string, callback: AsyncCallback\): void ```ts try { - panel.setUiContent('pages/page2/page2', (err: Error) => { + panel.setUiContent('pages/page2/page2', (err: BusinessError) => { if (err) { console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); return; @@ -1034,7 +1034,7 @@ setUiContent(path: string): Promise\ try { panel.setUiContent('pages/page2/page2').then(() => { console.log('Succeeded in setting the content.'); - }).catch((err: Error) => { + }).catch((err: BusinessError) => { console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); }); } catch (err) { @@ -1064,7 +1064,7 @@ setUiContent(path: string, storage: LocalStorage, callback: AsyncCallback\ let storage = new LocalStorage(); storage.setOrCreate('storageSimpleProp',121); try { - panel.setUiContent('pages/page2/page2', storage, (err: Error) => { + panel.setUiContent('pages/page2/page2', storage, (err: BusinessError) => { if (err) { console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); return; @@ -1105,7 +1105,7 @@ storage.setOrCreate('storageSimpleProp',121); try { panel.setUiContent('pages/page2/page2')then(() => { console.log('Succeeded in setting the content.'); - }).catch((err: Error) => { + }).catch((err: BusinessError) => { console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); }); } catch (err) { @@ -1137,7 +1137,7 @@ resize(width: number, height: number, callback: AsyncCallback\): void ```ts try { - panel.resize(500, 1000, (err: Error) => { + panel.resize(500, 1000, (err: BusinessError) => { if (err) { console.error(`Failed to resize panel: ${JSON.stringify(err)}`); return; @@ -1180,7 +1180,7 @@ resize(width: number, height: number): Promise\; try { panel.resize(500, 1000).then(() => { console.log('Succeeded in changing the panel size.'); - }).catch((err: Error) => { + }).catch((err: BusinessError) => { console.error(`Failed to resize panel: ${JSON.stringify(err)}`); }); } catch (err) { @@ -1208,7 +1208,7 @@ moveTo(x: number, y: number, callback: AsyncCallback\): void ```ts try { - panel.moveTo(300, 300, (err: Error) =>{ + panel.moveTo(300, 300, (err: BusinessError) =>{ if (err) { console.error(`Failed to move panel: ${JSON.stringify(err)}`); return; @@ -1247,7 +1247,7 @@ moveTo(x: number, y: number): Promise\ try { panel.moveTo(300, 300).then(() => { console.log('Succeeded in moving the panel.'); - }).catch((err: Error) => { + }).catch((err: BusinessError) => { console.error(`Failed to move panel: ${JSON.stringify(err)}`); }); } catch (err) { @@ -1272,7 +1272,7 @@ show(callback: AsyncCallback\): void **示例:** ```ts -panel.show((err: Error) => { +panel.show((err: BusinessError) => { if (err) { console.error(`Failed to show panel: ${JSON.stringify(err)}`); return; @@ -1300,7 +1300,7 @@ show(): Promise\ ```ts panel.show().then(() => { console.log('Succeeded in showing the panel.'); -}).catch((err: Error) => { +}).catch((err: BusinessError) => { console.error(`Failed to show panel: ${JSON.stringify(err)}`); }); ``` @@ -1322,7 +1322,7 @@ hide(callback: AsyncCallback\): void **示例:** ```ts -panel.hide((err: Error) => { +panel.hide((err: BusinessError) => { if (err) { console.error(`Failed to hide panel: ${JSON.stringify(err)}`); return; @@ -1350,7 +1350,7 @@ hide(): Promise\ ```ts panel.hide().then(() => { console.log('Succeeded in hiding the panel.'); -}).catch((err: Error) => { +}).catch((err: BusinessError) => { console.error(`Failed to hide panel: ${JSON.stringify(err)}`); }); ``` @@ -1493,7 +1493,7 @@ hide(callback: AsyncCallback<void>): void **示例:** ```ts -keyboardController.hide((err: Error) => { +keyboardController.hide((err: BusinessError) => { if (err) { console.error(`Failed to hide: ${JSON.stringify(err)}`); return; @@ -1529,7 +1529,7 @@ hide(): Promise<void> ```ts keyboardController.hide().then(() => { console.log('Succeeded in hiding keyboard.'); -}).catch((err: Error) => { +}).catch((err: BusinessError) => { console.log(`Failed to hide: ${JSON.stringify(err)}`); }); ``` @@ -1555,7 +1555,7 @@ hideKeyboard(callback: AsyncCallback<void>): void **示例:** ```ts -keyboardController.hideKeyboard((err: Error) => { +keyboardController.hideKeyboard((err: BusinessError) => { if (err) { console.error(`Failed to hideKeyboard: ${JSON.stringify(err)}`); return; @@ -1587,7 +1587,7 @@ hideKeyboard(): Promise<void> ```ts keyboardController.hideKeyboard().then(() => { console.log('Succeeded in hiding keyboard.'); -}).catch((err: Error) => { +}).catch((err: BusinessError) => { console.log(`Failed to hideKeyboard: ${JSON.stringify(err)}`); }); ``` @@ -1671,7 +1671,7 @@ sendKeyFunction(action:number, callback: AsyncCallback<boolean>): void ```ts let action = 1; try { - inputClient.sendKeyFunction(action, (err: Error, result: boolean) => { + inputClient.sendKeyFunction(action, (err: BusinessError, result: boolean) => { if (err) { console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); return; @@ -1726,7 +1726,7 @@ try { } else { console.error('Failed to sendKeyFunction.'); } - }).catch((err: Error) => { + }).catch((err: BusinessError) => { console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); }); } catch (err) { @@ -1763,7 +1763,7 @@ getForward(length:number, callback: AsyncCallback<string>): void ```ts let length = 1; try { - inputClient.getForward(length, (err: Error, text: string) => { + inputClient.getForward(length, (err: BusinessError, text: string) => { if (err) { console.error(`Failed to getForward: ${JSON.stringify(err)}`); return; @@ -1811,7 +1811,7 @@ let length = 1; try { inputClient.getForward(length).then((text: string) => { console.log('Succeeded in getting forward, text: ' + text); - }).catch((err: Error) => { + }).catch((err: BusinessError) => { console.error(`Failed to getForward: ${JSON.stringify(err)}`); }); } catch (err) { @@ -1889,7 +1889,7 @@ getBackward(length:number, callback: AsyncCallback<string>): void ```ts let length = 1; try { - inputClient.getBackward(length, (err: Error, text: string) => { + inputClient.getBackward(length, (err: BusinessError, text: string) => { if (err) { console.error(`Failed to getBackward: ${JSON.stringify(err)}`); return; @@ -1937,7 +1937,7 @@ let length = 1; try { inputClient.getBackward(length).then((text: string) => { console.log('Succeeded in getting backward, text: ' + text); - }).catch((err: Error) => { + }).catch((err: BusinessError) => { console.error(`Failed to getBackward: ${JSON.stringify(err)}`); }); } catch (err) { @@ -2015,7 +2015,7 @@ deleteForward(length:number, callback: AsyncCallback<boolean>): void ```ts let length = 1; try { - inputClient.deleteForward(length, (err: Error, result: boolean) => { + inputClient.deleteForward(length, (err: BusinessError, result: boolean) => { if (err) { console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); return; @@ -2071,7 +2071,7 @@ try { } else { console.error('Failed to delete Forward.'); } - }).catch((err: Error) => { + }).catch((err: BusinessError) => { console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); }); } catch (err) { @@ -2143,7 +2143,7 @@ deleteBackward(length:number, callback: AsyncCallback<boolean>): void ```ts let length = 1; try { - inputClient.deleteBackward(length, (err: Error, result: boolean) => { + inputClient.deleteBackward(length, (err: BusinessError, result: boolean) => { if (err) { console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`); return; @@ -2198,7 +2198,7 @@ inputClient.deleteBackward(length).then((result: boolean) => { } else { console.error('Failed to deleteBackward.'); } -}).catch((err: Error) => { +}).catch((err: BusinessError) => { console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`); }); ``` @@ -2265,7 +2265,7 @@ insertText(text:string, callback: AsyncCallback<boolean>): void **示例:** ```ts -inputClient.insertText('test', (err: Error, result: boolean) => { +inputClient.insertText('test', (err: BusinessError, result: boolean) => { if (err) { console.error(`Failed to insertText: ${JSON.stringify(err)}`); return; @@ -2317,7 +2317,7 @@ try { } else { console.error('Failed to insertText.'); } - }).catch((err: Error) => { + }).catch((err: BusinessError) => { console.error(`Failed to insertText: ${JSON.stringify(err)}`); }); } catch (err) { @@ -2384,7 +2384,7 @@ getEditorAttribute(callback: AsyncCallback<EditorAttribute>): void **示例:** ```ts -inputClient.getEditorAttribute((err: Error, editorAttribute: inputMethodEngine.EditorAttribute) => { +inputClient.getEditorAttribute((err: BusinessError, editorAttribute: inputMethodEngine.EditorAttribute) => { if (err) { console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`); return; @@ -2422,7 +2422,7 @@ getEditorAttribute(): Promise<EditorAttribute> inputClient.getEditorAttribute().then((editorAttribute: inputMethodEngine.EditorAttribute) => { console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); -}).catch((err: Error) => { +}).catch((err: BusinessError) => { console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`); }); ``` @@ -2487,7 +2487,7 @@ moveCursor(direction: number, callback: AsyncCallback<void>): void ```ts try { - inputClient.moveCursor(inputMethodEngine.Direction.CURSOR_UP, (err: Error) => { + inputClient.moveCursor(inputMethodEngine.Direction.CURSOR_UP, (err: BusinessError) => { if (err) { console.error(`Failed to moveCursor: ${JSON.stringify(err)}`); return; @@ -2533,7 +2533,7 @@ moveCursor(direction: number): Promise<void> try { inputClient.moveCursor(inputMethodEngine.Direction.CURSOR_UP).then(() => { console.log('Succeeded in moving cursor.'); - }).catch((err: Error) => { + }).catch((err: BusinessError) => { console.error(`Failed to moveCursor: ${JSON.stringify(err)}`); }); } catch (err) { @@ -2603,7 +2603,7 @@ selectByRange(range: Range, callback: AsyncCallback<void>): void ```ts try { let range: inputMethodEngine.Range = { start: 0, end: 1 }; - inputClient.selectByRange(range, (err: Error) => { + inputClient.selectByRange(range, (err: BusinessError) => { if (err) { console.error(`Failed to selectByRange: ${JSON.stringify(err)}`); return; @@ -2651,7 +2651,7 @@ try { let range: inputMethodEngine.Range = { start: 0, end: 1 }; inputClient.selectByRange(range).then(() => { console.log('Succeeded in selecting by range.'); - }).catch((err: Error) => { + }).catch((err: BusinessError) => { console.error(`Failed to selectByRange: ${JSON.stringify(err)}`); }); } catch (err) { @@ -2723,7 +2723,7 @@ selectByMovement(movement: Movement, callback: AsyncCallback<void>): void ```ts try { let movement: inputMethodEngine.Movement = { direction: 1 }; - inputClient.selectByMovement(movement, (err: Error) => { + inputClient.selectByMovement(movement, (err: BusinessError) => { if (err) { console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`); return; @@ -2771,7 +2771,7 @@ try { let movement: inputMethodEngine.Movement = { direction: 1 }; inputClient.selectByMovement(movement).then(() => { console.log('Succeeded in selecting by movement.'); - }).catch((err: Error) => { + }).catch((err: BusinessError) => { console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`); }); } catch (err) { @@ -2840,7 +2840,7 @@ getTextIndexAtCursor(callback: AsyncCallback<number>): void **示例:** ```ts -inputClient.getTextIndexAtCursor((err: Error, index: number) => { +inputClient.getTextIndexAtCursor((err: BusinessError, index: number) => { if (err) { console.error(`Failed to getTextIndexAtCursor: ${JSON.stringify(err)}`); return; @@ -2877,7 +2877,7 @@ getTextIndexAtCursor(): Promise<number> ```ts inputClient.getTextIndexAtCursor().then((index: number) => { console.log('Succeeded in getTextIndexAtCursor: ' + index); -}).catch((err: Error) => { +}).catch((err: BusinessError) => { console.error(`Failed to getTextIndexAtCursor: ${JSON.stringify(err)}`); }); ``` @@ -2948,7 +2948,7 @@ sendExtendAction(action: ExtendAction, callback: AsyncCallback<void>): voi ```ts try { - inputClient.sendExtendAction(inputMethodEngine.ExtendAction.COPY, (err: Error) => { + inputClient.sendExtendAction(inputMethodEngine.ExtendAction.COPY, (err: BusinessError) => { if (err) { console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`); return; @@ -2999,7 +2999,7 @@ sendExtendAction(action: ExtendAction): Promise<void> try { inputClient.sendExtendAction(inputMethodEngine.ExtendAction.COPY).then(() => { console.log('Succeeded in sending extend action.'); - }).catch((err: Error) => { + }).catch((err: BusinessError) => { console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`); }); } catch(err) { @@ -3093,7 +3093,7 @@ getForward(length:number, callback: AsyncCallback<string>): void ```ts let length = 1; -textInputClient.getForward(length, (err: Error, text: string) => { +textInputClient.getForward(length, (err: BusinessError, text: string) => { if (err) { console.error(`Failed to getForward: ${JSON.stringify(err)}`); return; @@ -3132,7 +3132,7 @@ getForward(length:number): Promise<string> let length = 1; textInputClient.getForward(length).then((text: string) => { console.log('Succeeded in getting forward, text: ' + text); -}).catch((err: Error) => { +}).catch((err: BusinessError) => { console.error(`Failed to getForward: ${JSON.stringify(err)}`); }); ``` @@ -3160,7 +3160,7 @@ getBackward(length:number, callback: AsyncCallback<string>): void ```ts let length = 1; -textInputClient.getBackward(length, (err: Error, text: string) => { +textInputClient.getBackward(length, (err: BusinessError, text: string) => { if (err) { console.error(`Failed to getBackward: ${JSON.stringify(err)}`); return; @@ -3199,7 +3199,7 @@ getBackward(length:number): Promise<string> let length = 1; textInputClient.getBackward(length).then((text: string) => { console.log('Succeeded in getting backward: ' + JSON.stringify(text)); -}).catch((err: Error) => { +}).catch((err: BusinessError) => { console.error(`Failed to getBackward: ${JSON.stringify(err)}`); }); ``` @@ -3227,7 +3227,7 @@ deleteForward(length:number, callback: AsyncCallback<boolean>): void ```ts let length = 1; -textInputClient.deleteForward(length, (err: Error, result: boolean) => { +textInputClient.deleteForward(length, (err: BusinessError, result: boolean) => { if (err) { console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); return; @@ -3274,7 +3274,7 @@ textInputClient.deleteForward(length).then((result: boolean) => { } else { console.error('Failed to delete forward.'); } -}).catch((err: Error) => { +}).catch((err: BusinessError) => { console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); }); ``` @@ -3302,7 +3302,7 @@ deleteBackward(length:number, callback: AsyncCallback<boolean>): void ```ts let length = 1; -textInputClient.deleteBackward(length, (err: Error, result: boolean) => { +textInputClient.deleteBackward(length, (err: BusinessError, result: boolean) => { if (err) { console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`); return; @@ -3349,7 +3349,7 @@ textInputClient.deleteBackward(length).then((result: boolean) => { } else { console.error('Failed to deleteBackward.'); } -}).catch((err: Error) => { +}).catch((err: BusinessError) => { console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`); }); ``` @@ -3376,7 +3376,7 @@ sendKeyFunction(action: number, callback: AsyncCallback<boolean>): void ```ts let action = 1; -textInputClient.sendKeyFunction(action, (err: Error, result: boolean) => { +textInputClient.sendKeyFunction(action, (err: BusinessError, result: boolean) => { if (err) { console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); return; @@ -3423,7 +3423,7 @@ textInputClient.sendKeyFunction(action).then((result: boolean) => { } else { console.error('Failed to sendKeyFunction.'); } -}).catch((err: Error) => { +}).catch((err: BusinessError) => { console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); }); ``` @@ -3450,7 +3450,7 @@ insertText(text:string, callback: AsyncCallback<boolean>): void **示例:** ```ts -textInputClient.insertText('test', (err: Error, result: boolean) => { +textInputClient.insertText('test', (err: BusinessError, result: boolean) => { if (err) { console.error(`Failed to insertText: ${JSON.stringify(err)}`); return; @@ -3496,7 +3496,7 @@ textInputClient.insertText('test').then((result: boolean) => { } else { console.error('Failed to insertText.'); } -}).catch((err: Error) => { +}).catch((err: BusinessError) => { console.error(`Failed to insertText: ${JSON.stringify(err)}`); }); ``` @@ -3522,7 +3522,7 @@ getEditorAttribute(callback: AsyncCallback<EditorAttribute>): void **示例:** ```ts -textInputClient.getEditorAttribute((err: Error, editorAttribute: inputMethodEngine.EditorAttribute) => { +textInputClient.getEditorAttribute((err: BusinessError, editorAttribute: inputMethodEngine.EditorAttribute) => { if (err) { console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`); return; @@ -3556,7 +3556,7 @@ getEditorAttribute(): Promise<EditorAttribute> textInputClient.getEditorAttribute().then((editorAttribute: inputMethodEngine.EditorAttribute) => { console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); -}).catch((err: Error) => { +}).catch((err: BusinessError) => { console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`); }); ``` diff --git a/zh-cn/application-dev/reference/apis/js-apis-request.md b/zh-cn/application-dev/reference/apis/js-apis-request.md index a90f3503a1b626b9e877fcbffd4d65ebb1e89a8e..675c5eeac1fa08ad67767dbcf43b4011b0c02988 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-request.md +++ b/zh-cn/application-dev/reference/apis/js-apis-request.md @@ -103,10 +103,9 @@ uploadFile(context: BaseContext, config: UploadConfig): Promise<UploadTask> **示例:** - ```js - let uploadTask; - let context; - let uploadConfig = { + ```ts + let uploadTask: request.UploadTask; + let uploadConfig: request.UploadConfig = { url: 'http://patch', header: { key1: "value1", key2: "value2" }, method: "POST", @@ -114,13 +113,13 @@ uploadFile(context: BaseContext, config: UploadConfig): Promise<UploadTask> data: [{ name: "name123", value: "123" }], }; try { - request.uploadFile(context, uploadConfig).then((data) => { + request.uploadFile(this.context, uploadConfig).then((data: request.UploadTask) => { uploadTask = data; - }).catch((err) => { + }).catch((err: BusinessError) => { console.error(`Failed to request the upload. Code: ${err.code}, message: ${err.message}`); }); } catch (err) { - console.error(`Failed to request the upload. Code: ${err.code}, message: ${err.message}`); + console.error(`Failed to request the upload. err: ${JSON.stringify(err)}`); } ``` @@ -157,10 +156,9 @@ uploadFile(context: BaseContext, config: UploadConfig, callback: AsyncCallback&l **示例:** - ```js - let uploadTask; - let context; - let uploadConfig = { + ```ts + let uploadTask: request.UploadTask; + let uploadConfig: request.UploadConfig = { url: 'http://patch', header: { key1: "value1", key2: "value2" }, method: "POST", @@ -168,7 +166,7 @@ uploadFile(context: BaseContext, config: UploadConfig, callback: AsyncCallback&l data: [{ name: "name123", value: "123" }], }; try { - request.uploadFile(context, uploadConfig, (err, data) => { + request.uploadFile(this.context, uploadConfig, (err: BusinessError, data: request.UploadTask) => { if (err) { console.error(`Failed to request the upload. Code: ${err.code}, message: ${err.message}`); return; @@ -176,7 +174,7 @@ uploadFile(context: BaseContext, config: UploadConfig, callback: AsyncCallback&l uploadTask = data; }); } catch (err) { - console.error(`Failed to request the upload. Code: ${err.code}, message: ${err.message}`); + console.error(`Failed to request the upload. err: ${JSON.stringify(err)}`); } ``` @@ -306,8 +304,8 @@ on(type: 'progress', callback:(uploadedSize: number, totalSize: number) => vo **示例:** - ```js - let upProgressCallback = (uploadedSize, totalSize) => { + ```ts + let upProgressCallback = (uploadedSize: number, totalSize: number) => { console.info("upload totalSize:" + totalSize + " uploadedSize:" + uploadedSize); }; uploadTask.on('progress', upProgressCallback); @@ -339,8 +337,8 @@ on(type: 'headerReceive', callback: (header: object) => void): void **示例:** - ```js - let headerCallback = (headers) => { + ```ts + let headerCallback = (headers: object) => { console.info("upOnHeader headers:" + JSON.stringify(headers)); }; uploadTask.on('headerReceive', headerCallback); @@ -372,16 +370,16 @@ on(type: 'headerReceive', callback: (header: object) => void): void **示例:** - ```js - let upCompleteCallback = (taskStates) => { - for (let i = 0; i < taskStates.length; i++ ) { + ```ts + let upCompleteCallback = (taskStates: Array) => { + for (let i = 0; i < taskStates.length; i++) { console.info("upOnComplete taskState:" + JSON.stringify(taskStates[i])); } }; uploadTask.on('complete', upCompleteCallback); - let upFailCallback = (taskStates) => { - for (let i = 0; i < taskStates.length; i++ ) { + let upFailCallback = (taskStates: Array) => { + for (let i = 0; i < taskStates.length; i++) { console.info("upOnFail taskState:" + JSON.stringify(taskStates[i])); } }; @@ -408,8 +406,8 @@ off(type: 'progress', callback?: (uploadedSize: number, totalSize: number) =&g **示例:** - ```js - let upProgressCallback = (uploadedSize, totalSize) => { + ```ts + let upProgressCallback = (uploadedSize: number, totalSize: number) => { console.info('Upload delete progress notification.' + 'totalSize:' + totalSize + 'uploadedSize:' + uploadedSize); }; uploadTask.off('progress', upProgressCallback); @@ -435,8 +433,8 @@ off(type: 'headerReceive', callback?: (header: object) => void): void **示例:** - ```js - let headerCallback = (header) => { + ```ts + let headerCallback = (header: object) => { console.info(`Upload delete headerReceive notification. header: ${JSON.stringify(header)}`); }; uploadTask.off('headerReceive', headerCallback); @@ -461,18 +459,18 @@ off(type: 'headerReceive', callback?: (header: object) => void): void **示例:** - ```js - let upCompleteCallback = (taskStates) => { + ```ts + let upCompleteCallback = (taskStates: Array) => { console.info('Upload delete complete notification.'); - for (let i = 0; i < taskStates.length; i++ ) { + for (let i = 0; i < taskStates.length; i++) { console.info('taskState:' + JSON.stringify(taskStates[i])); } }; uploadTask.off('complete', upCompleteCallback); - let upFailCallback = (taskStates) => { + let upFailCallback = (taskStates: Array) => { console.info('Upload delete fail notification.'); - for (let i = 0; i < taskStates.length; i++ ) { + for (let i = 0; i < taskStates.length; i++) { console.info('taskState:' + JSON.stringify(taskStates[i])); } }; @@ -496,10 +494,10 @@ delete(): Promise<boolean> **示例:** - ```js - uploadTask.delete().then((result) => { + ```ts + uploadTask.delete().then((result: boolean) => { console.info('Succeeded in deleting the upload task.'); - }).catch((err) => { + }).catch((err: BusinessError) => { console.error(`Failed to delete the upload task. Code: ${err.code}, message: ${err.message}`); }); ``` @@ -523,8 +521,8 @@ delete(callback: AsyncCallback<boolean>): void **示例:** - ```js - uploadTask.delete((err, result) => { + ```ts + uploadTask.delete((err: BusinessError, result: boolean) => { if (err) { console.error(`Failed to delete the upload task. Code: ${err.code}, message: ${err.message}`); return; @@ -688,17 +686,16 @@ downloadFile(context: BaseContext, config: DownloadConfig): Promise<DownloadT **示例:** - ```js - let downloadTask; - let context; + ```ts + let downloadTask: request.DownloadTask; try { - request.downloadFile(context, { url: 'https://xxxx/xxxx.hap' }).then((data) => { + request.downloadFile(this.context, { url: 'https://xxxx/xxxx.hap' }).then((data: request.DownloadTask) => { downloadTask = data; - }).catch((err) => { + }).catch((err: BusinessError) => { console.error(`Failed to request the download. Code: ${err.code}, message: ${err.message}`); }) } catch (err) { - console.error(`Failed to request the download. Code: ${err.code}, message: ${err.message}`); + console.error(`Failed to request the download. err: ${JSON.stringify(err)}`); } ``` @@ -738,12 +735,13 @@ downloadFile(context: BaseContext, config: DownloadConfig, callback: AsyncCallba **示例:** - ```js - let downloadTask; - let context; + ```ts + let downloadTask: request.DownloadTask; try { - request.downloadFile(context, { url: 'https://xxxx/xxxxx.hap', - filePath: 'xxx/xxxxx.hap'}, (err, data) => { + request.downloadFile(this.context, { + url: 'https://xxxx/xxxxx.hap', + filePath: 'xxx/xxxxx.hap' + }, (err: BusinessError, data: request.DownloadTask) => { if (err) { console.error(`Failed to request the download. Code: ${err.code}, message: ${err.message}`); return; @@ -751,7 +749,7 @@ downloadFile(context: BaseContext, config: DownloadConfig, callback: AsyncCallba downloadTask = data; }); } catch (err) { - console.error(`Failed to request the download. Code: ${err.code}, message: ${err.message}`); + console.error(`Failed to request the download. err: ${JSON.stringify(err)}`); } ``` @@ -867,8 +865,8 @@ on(type: 'progress', callback:(receivedSize: number, totalSize: number) => vo **示例:** - ```js - let progresCallback = (receivedSize, totalSize) => { + ```ts + let progresCallback = (receivedSize: number, totalSize: number) => { console.info("download receivedSize:" + receivedSize + " totalSize:" + totalSize); }; downloadTask.on('progress', progresCallback); @@ -894,8 +892,8 @@ off(type: 'progress', callback?: (receivedSize: number, totalSize: number) => **示例:** - ```js - let progresCallback = (receivedSize, totalSize) => { + ```ts + let progresCallback = (receivedSize: number, totalSize: number) => { console.info('Download delete progress notification.' + 'receivedSize:' + receivedSize + 'totalSize:' + totalSize); }; downloadTask.off('progress', progresCallback); @@ -921,7 +919,7 @@ on(type: 'complete'|'pause'|'remove', callback:() => void): void **示例:** - ```js + ```ts let completeCallback = () => { console.info('Download task completed.'); }; @@ -958,7 +956,7 @@ off(type: 'complete'|'pause'|'remove', callback?:() => void): void **示例:** - ```js + ```ts let completeCallback = () => { console.info('Download delete complete notification.'); }; @@ -1001,8 +999,8 @@ on(type: 'fail', callback: (err: number) => void): void **示例:** - ```js - let failCallback = (err) => { + ```ts + let failCallback = (err: BusinessError) => { console.error(`Failed to download the task. Code: ${err.code}, message: ${err.message}`); }; downloadTask.on('fail', failCallback); @@ -1028,8 +1026,8 @@ off(type: 'fail', callback?: (err: number) => void): void **示例:** - ```js - let failCallback = (err) => { + ```ts + let failCallback = (err: BusinessError) => { console.error(`Failed to download the task. Code: ${err.code}, message: ${err.message}`); }; downloadTask.off('fail', failCallback); @@ -1053,10 +1051,10 @@ delete(): Promise<boolean> **示例:** - ```js - downloadTask.delete().then((result) => { + ```ts + downloadTask.delete().then((result: boolean) => { console.info('Succeeded in removing the download task.'); - }).catch ((err) => { + }).catch((err: BusinessError) => { console.error(`Failed to remove the download task. Code: ${err.code}, message: ${err.message}`); }); ``` @@ -1080,12 +1078,12 @@ delete(callback: AsyncCallback<boolean>): void **示例:** - ```js - downloadTask.delete((err, result)=>{ - if(err) { + ```ts + downloadTask.delete((err: BusinessError, result: boolean) => { + if (err) { console.error(`Failed to remove the download task. Code: ${err.code}, message: ${err.message}`); return; - } + } console.info('Succeeded in removing the download task.'); }); ``` @@ -1109,10 +1107,10 @@ getTaskInfo(): Promise<DownloadInfo> **示例:** - ```js - downloadTask.getTaskInfo().then((downloadInfo) => { + ```ts + downloadTask.getTaskInfo().then((downloadInfo: request.DownloadInfo) => { console.info('Succeeded in querying the download task') - }) .catch((err) => { + }).catch((err: BusinessError) => { console.error(`Failed to query the download task. Code: ${err.code}, message: ${err.message}`) }); ``` @@ -1136,9 +1134,9 @@ getTaskInfo(callback: AsyncCallback<DownloadInfo>): void **示例:** - ```js - downloadTask.getTaskInfo((err, downloadInfo)=>{ - if(err) { + ```ts + downloadTask.getTaskInfo((err: BusinessError, downloadInfo: request.DownloadInfo) => { + if (err) { console.error(`Failed to query the download mimeType. Code: ${err.code}, message: ${err.message}`); } else { console.info('Succeeded in querying the download mimeType'); @@ -1165,10 +1163,10 @@ getTaskMimeType(): Promise<string> **示例:** - ```js - downloadTask.getTaskMimeType().then((data) => { + ```ts + downloadTask.getTaskMimeType().then((data: string) => { console.info('Succeeded in querying the download MimeType'); - }).catch((err) => { + }).catch((err: BusinessError) => { console.error(`Failed to query the download MimeType. Code: ${err.code}, message: ${err.message}`) }); ``` @@ -1192,9 +1190,9 @@ getTaskMimeType(callback: AsyncCallback<string>): void; **示例:** - ```js - downloadTask.getTaskMimeType((err, data)=>{ - if(err) { + ```ts + downloadTask.getTaskMimeType((err: BusinessError, data: string) => { + if (err) { console.error(`Failed to query the download mimeType. Code: ${err.code}, message: ${err.message}`); } else { console.info('Succeeded in querying the download mimeType'); @@ -1221,10 +1219,10 @@ suspend(): Promise<boolean> **示例:** - ```js - downloadTask.suspend().then((result) => { + ```ts + downloadTask.suspend().then((result: boolean) => { console.info('Succeeded in pausing the download task.'); - }).catch((err) => { + }).catch((err: BusinessError) => { console.error(`Failed to pause the download task. Code: ${err.code}, message: ${err.message}`); }); ``` @@ -1248,9 +1246,9 @@ suspend(callback: AsyncCallback<boolean>): void **示例:** - ```js - downloadTask.suspend((err, result)=>{ - if(err) { + ```ts + downloadTask.suspend((err: BusinessError, result: boolean) => { + if (err) { console.error(`Failed to pause the download task. Code: ${err.code}, message: ${err.message}`); return; } @@ -1277,10 +1275,10 @@ restore(): Promise<boolean> **示例:** - ```js - downloadTask.restore().then((result) => { + ```ts + downloadTask.restore().then((result: boolean) => { console.info('Succeeded in resuming the download task.') - }).catch((err) => { + }).catch((err: BusinessError) => { console.error(`Failed to resume the download task. Code: ${err.code}, message: ${err.message}`); }); ``` @@ -1304,12 +1302,12 @@ restore(callback: AsyncCallback<boolean>): void **示例:** - ```js - downloadTask.restore((err, result)=>{ + ```ts + downloadTask.restore((err: BusinessError, result: boolean) => { if (err) { console.error(`Failed to resume the download task. Code: ${err.code}, message: ${err.message}`); return; - } + } console.info('Succeeded in resuming the download task.'); }); ``` @@ -1874,17 +1872,16 @@ on(event: 'progress', callback: (progress: Progress) => void): void **示例:** - ```js - let context; - let attachments = [{ - name: "taskOnTest", - value: { - filename: "taskOnTest.avi", - mimetype: "application/octet-stream", - path: "./taskOnTest.avi", - } - }]; - let config = { + ```ts + let attachments: Array = [{ + name: "taskOnTest", + value: { + filename: "taskOnTest.avi", + mimeType: "application/octet-stream", + path: "./taskOnTest.avi", + } + }]; + let config: request.agent.Config = { action: request.agent.Action.UPLOAD, url: 'http://127.0.0.1', title: 'taskOnTest', @@ -1906,13 +1903,13 @@ on(event: 'progress', callback: (progress: Progress) => void): void precise: false, token: "it is a secret" }; - let createOnCallback = (progress) => { - console.info('upload task completed.'); + let createOnCallback = (progress: request.agent.Progress) => { + console.info('upload task progress.'); }; - request.agent.create(context, config).then((task)=> { + request.agent.create(this.context, config).then((task: request.agent.Task) => { task.on('progress', createOnCallback); console.info(`Succeeded in creating a upload task. result: ${task.tid}`); - }).catch((err) => { + }).catch((err: BusinessError) => { console.error(`Failed to create a upload task, Code: ${err.code}, message: ${err.message}`); }); ``` @@ -1946,17 +1943,16 @@ on(event: 'completed', callback: (progress: Progress) => void): void **示例:** - ```js - let context; - let attachments = [{ - name: "taskOnTest", - value: { - filename: "taskOnTest.avi", - mimetype: "application/octet-stream", - path: "./taskOnTest.avi", - } - }]; - let config = { + ```ts + let attachments: Array = [{ + name: "taskOnTest", + value: { + filename: "taskOnTest.avi", + mimeType: "application/octet-stream", + path: "./taskOnTest.avi", + } + }]; + let config: request.agent.Config = { action: request.agent.Action.UPLOAD, url: 'http://127.0.0.1', title: 'taskOnTest', @@ -1978,13 +1974,13 @@ on(event: 'completed', callback: (progress: Progress) => void): void precise: false, token: "it is a secret" }; - let createOnCallback = (progress) => { + let createOnCallback = (progress: request.agent.Progress) => { console.info('upload task completed.'); }; - request.agent.create(context, config).then((task)=> { + request.agent.create(this.context, config).then((task: request.agent.Task) => { task.on('completed', createOnCallback); console.info(`Succeeded in creating a upload task. result: ${task.tid}`); - }).catch((err) => { + }).catch((err: BusinessError) => { console.error(`Failed to create a upload task, Code: ${err.code}, message: ${err.message}`); }); ``` @@ -2018,17 +2014,16 @@ on(event: 'failed', callback: (progress: Progress) => void): void **示例:** - ```js - let context; - let attachments = [{ - name: "taskOnTest", - value: { - filename: "taskOnTest.avi", - mimetype: "application/octet-stream", - path: "./taskOnTest.avi", - } - }]; - let config = { + ```ts + let attachments: Array = [{ + name: "taskOnTest", + value: { + filename: "taskOnTest.avi", + mimeType: "application/octet-stream", + path: "./taskOnTest.avi", + } + }]; + let config: request.agent.Config = { action: request.agent.Action.UPLOAD, url: 'http://127.0.0.1', title: 'taskOnTest', @@ -2050,13 +2045,13 @@ on(event: 'failed', callback: (progress: Progress) => void): void precise: false, token: "it is a secret" }; - let createOnCallback = (progress) => { - console.info('upload task completed.'); + let createOnCallback = (progress: request.agent.Progress) => { + console.info('upload task failed.'); }; - request.agent.create(context, config).then((task)=> { + request.agent.create(this.context, config).then((task: request.agent.Task) => { task.on('failed', createOnCallback); console.info(`Succeeded in creating a upload task. result: ${task.tid}`); - }).catch((err) => { + }).catch((err: BusinessError) => { console.error(`Failed to create a upload task, Code: ${err.code}, message: ${err.message}`); }); ``` @@ -2091,17 +2086,16 @@ off(event: 'progress', callback?: (progress: Progress) => void): void **示例:** - ```js - let context; - let attachments = [{ - name: "taskOffTest", - value: { - filename: "taskOffTest.avi", - mimetype: "application/octet-stream", - path: "./taskOffTest.avi", - } - }]; - let config = { + ```ts + let attachments: Array = [{ + name: "taskOffTest", + value: { + filename: "taskOffTest.avi", + mimeType: "application/octet-stream", + path: "./taskOffTest.avi", + } + }]; + let config: request.agent.Config = { action: request.agent.Action.UPLOAD, url: 'http://127.0.0.1', title: 'taskOffTest', @@ -2123,14 +2117,14 @@ off(event: 'progress', callback?: (progress: Progress) => void): void precise: false, token: "it is a secret" }; - let createOffCallback = (progress) => { - console.info('upload task completed.'); + let createOffCallback = (progress: request.agent.Progress) => { + console.info('upload task progress.'); }; - request.agent.create(context, config).then((task)=> { + request.agent.create(this.context, config).then((task: request.agent.Task) => { task.on('progress', createOffCallback); task.off('progress', createOffCallback); console.info(`Succeeded in creating a upload task. result: ${task.tid}`); - }).catch((err) => { + }).catch((err: BusinessError) => { console.error(`Failed to create a upload task, Code: ${err.code}, message: ${err.message}`); }); ``` @@ -2164,17 +2158,16 @@ off(event: 'completed', callback?: (progress: Progress) => void): void **示例:** - ```js - let context; - let attachments = [{ - name: "taskOffTest", - value: { - filename: "taskOffTest.avi", - mimetype: "application/octet-stream", - path: "./taskOffTest.avi", - } - }]; - let config = { + ```ts + let attachments: Array = [{ + name: "taskOffTest", + value: { + filename: "taskOffTest.avi", + mimeType: "application/octet-stream", + path: "./taskOffTest.avi", + } + }]; + let config: request.agent.Config = { action: request.agent.Action.UPLOAD, url: 'http://127.0.0.1', title: 'taskOffTest', @@ -2196,14 +2189,14 @@ off(event: 'completed', callback?: (progress: Progress) => void): void precise: false, token: "it is a secret" }; - let createOffCallback = (progress) => { + let createOffCallback = (progress: request.agent.Progress) => { console.info('upload task completed.'); }; - request.agent.create(context, config).then((task)=> { + request.agent.create(this.context, config).then((task: request.agent.Task) => { task.on('completed', createOffCallback); task.off('completed', createOffCallback); console.info(`Succeeded in creating a upload task. result: ${task.tid}`); - }).catch((err) => { + }).catch((err: BusinessError) => { console.error(`Failed to create a upload task, Code: ${err.code}, message: ${err.message}`); }); ``` @@ -2237,17 +2230,16 @@ off(event: 'failed', callback?: (progress: Progress) => void): void **示例:** - ```js - let context; - let attachments = [{ - name: "taskOffTest", - value: { - filename: "taskOffTest.avi", - mimetype: "application/octet-stream", - path: "./taskOffTest.avi", - } - }]; - let config = { + ```ts + let attachments: Array = [{ + name: "taskOffTest", + value: { + filename: "taskOffTest.avi", + mimeType: "application/octet-stream", + path: "./taskOffTest.avi", + } + }]; + let config: request.agent.Config = { action: request.agent.Action.UPLOAD, url: 'http://127.0.0.1', title: 'taskOffTest', @@ -2269,14 +2261,14 @@ off(event: 'failed', callback?: (progress: Progress) => void): void precise: false, token: "it is a secret" }; - let createOffCallback = (progress) => { - console.info('upload task completed.'); + let createOffCallback = (progress: request.agent.Progress) => { + console.info('upload task failed.'); }; - request.agent.create(context, config).then((task)=> { + request.agent.create(this.context, config).then((task: request.agent.Task) => { task.on('failed', createOffCallback); task.off('failed', createOffCallback); console.info(`Succeeded in creating a upload task. result: ${task.tid}`); - }).catch((err) => { + }).catch((err: BusinessError) => { console.error(`Failed to create a upload task, Code: ${err.code}, message: ${err.message}`); }); ``` @@ -2312,9 +2304,8 @@ start(callback: AsyncCallback<void>): void **示例:** - ```js - let context; - let config = { + ```ts + let config: request.agent.Config = { action: request.agent.Action.DOWNLOAD, url: 'http://127.0.0.1', title: 'taskStartTest', @@ -2336,8 +2327,8 @@ start(callback: AsyncCallback<void>): void precise: false, token: "it is a secret" }; - request.agent.create(context, config).then((task) => { - task.start((err) => { + request.agent.create(this.context, config).then((task: request.agent.Task) => { + task.start((err: BusinessError) => { if (err) { console.error(`Failed to start the download task, Code: ${err.code}, message: ${err.message}`); return; @@ -2345,7 +2336,7 @@ start(callback: AsyncCallback<void>): void console.info(`Succeeded in starting a download task.`); }); console.info(`Succeeded in creating a download task. result: ${task.tid}`); - }).catch((err) => { + }).catch((err: BusinessError) => { console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`); }); ``` @@ -2381,9 +2372,8 @@ start(): Promise<void> **示例:** - ```js - let context; - let config = { + ```ts + let config: request.agent.Config = { action: request.agent.Action.DOWNLOAD, url: 'http://127.0.0.1', title: 'taskStartTest', @@ -2405,14 +2395,14 @@ start(): Promise<void> precise: false, token: "it is a secret" }; - request.agent.create(context, config).then((task) => { + request.agent.create(this.context, config).then((task: request.agent.Task) => { task.start().then(() => { console.info(`Succeeded in starting a download task.`); - }).catch((err) => { + }).catch((err: BusinessError) => { console.error(`Failed to start the download task, Code: ${err.code}, message: ${err.message}`); }); console.info(`Succeeded in creating a download task. result: ${task.tid}`); - }).catch((err) => { + }).catch((err: BusinessError) => { console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`); }); ``` @@ -2447,9 +2437,8 @@ pause(callback: AsyncCallback<void>): void **示例:** - ```js - let context; - let config = { + ```ts + let config: request.agent.Config = { action: request.agent.Action.DOWNLOAD, url: 'http://127.0.0.1', title: 'taskPauseTest', @@ -2471,8 +2460,8 @@ pause(callback: AsyncCallback<void>): void precise: false, token: "it is a secret" }; - request.agent.create(context, config).then((task) => { - task.pause((err) => { + request.agent.create(this.context, config).then((task: request.agent.Task) => { + task.pause((err: BusinessError) => { if (err) { console.error(`Failed to pause the download task, Code: ${err.code}, message: ${err.message}`); return; @@ -2480,7 +2469,7 @@ pause(callback: AsyncCallback<void>): void console.info(`Succeeded in pausing a download task. `); }); console.info(`Succeeded in creating a download task. result: ${task.tid}`); - }).catch((err) => { + }).catch((err: BusinessError) => { console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`); }); ``` @@ -2512,9 +2501,8 @@ pause(): Promise<void> **示例:** - ```js - let context; - let config = { + ```ts + let config: request.agent.Config = { action: request.agent.Action.DOWNLOAD, url: 'http://127.0.0.1', title: 'taskPauseTest', @@ -2536,14 +2524,14 @@ pause(): Promise<void> precise: false, token: "it is a secret" }; - request.agent.create(context, config).then((task) => { + request.agent.create(this.context, config).then((task: request.agent.Task) => { task.pause().then(() => { console.info(`Succeeded in pausing a download task. `); - }).catch((err) => { + }).catch((err: BusinessError) => { console.error(`Failed to pause the upload task, Code: ${err.code}, message: ${err.message}`); }); console.info(`Succeeded in creating a download task. result: ${task.tid}`); - }).catch((err) => { + }).catch((err: BusinessError) => { console.error(`Failed to create a upload task, Code: ${err.code}, message: ${err.message}`); }); ``` @@ -2577,9 +2565,8 @@ resume(callback: AsyncCallback<void>): void **示例:** - ```js - let context; - let config = { + ```ts + let config: request.agent.Config = { action: request.agent.Action.DOWNLOAD, url: 'http://127.0.0.1', title: 'taskResumeTest', @@ -2601,8 +2588,8 @@ resume(callback: AsyncCallback<void>): void precise: false, token: "it is a secret" }; - request.agent.create(context, config).then((task) => { - task.resume((err) => { + request.agent.create(this.context, config).then((task: request.agent.Task) => { + task.resume((err: BusinessError) => { if (err) { console.error(`Failed to resume the download task, Code: ${err.code}, message: ${err.message}`); return; @@ -2610,7 +2597,7 @@ resume(callback: AsyncCallback<void>): void console.info(`Succeeded in resuming a download task. `); }); console.info(`Succeeded in creating a download task. result: ${task.tid}`); - }).catch((err) => { + }).catch((err: BusinessError) => { console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`); }); ``` @@ -2644,9 +2631,8 @@ resume(): Promise<void> **示例:** - ```js - let context; - let config = { + ```ts + let config: request.agent.Config = { action: request.agent.Action.DOWNLOAD, url: 'http://127.0.0.1', title: 'taskResumeTest', @@ -2668,14 +2654,14 @@ resume(): Promise<void> precise: false, token: "it is a secret" }; - request.agent.create(context, config).then((task) => { + request.agent.create(this.context, config).then((task: request.agent.Task) => { task.resume().then(() => { console.info(`Succeeded in resuming a download task. `); - }).catch((err) => { + }).catch((err: BusinessError) => { console.error(`Failed to resume the download task, Code: ${err.code}, message: ${err.message}`); }); console.info(`Succeeded in creating a download task. result: ${task.tid}`); - }).catch((err) => { + }).catch((err: BusinessError) => { console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`); }); ``` @@ -2706,9 +2692,8 @@ stop(callback: AsyncCallback<void>): void **示例:** - ```js - let context; - let config = { + ```ts + let config: request.agent.Config = { action: request.agent.Action.DOWNLOAD, url: 'http://127.0.0.1', title: 'taskStopTest', @@ -2730,8 +2715,8 @@ stop(callback: AsyncCallback<void>): void precise: false, token: "it is a secret" }; - request.agent.create(context, config).then((task) => { - task.stop((err) => { + request.agent.create(this.context, config).then((task: request.agent.Task) => { + task.stop((err: BusinessError) => { if (err) { console.error(`Failed to stop the download task, Code: ${err.code}, message: ${err.message}`); return; @@ -2739,7 +2724,7 @@ stop(callback: AsyncCallback<void>): void console.info(`Succeeded in stopping a download task. `); }); console.info(`Succeeded in creating a download task. result: ${task.tid}`); - }).catch((err) => { + }).catch((err: BusinessError) => { console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`); }); ``` @@ -2770,9 +2755,8 @@ stop(): Promise<void> **示例:** - ```js - let context; - let config = { + ```ts + let config: request.agent.Config = { action: request.agent.Action.DOWNLOAD, url: 'http://127.0.0.1', title: 'taskStopTest', @@ -2794,14 +2778,14 @@ stop(): Promise<void> precise: false, token: "it is a secret" }; - request.agent.create(context, config).then((task) => { + request.agent.create(this.context, config).then((task: request.agent.Task) => { task.stop().then(() => { console.info(`Succeeded in stopping a download task. `); - }).catch((err) => { + }).catch((err: BusinessError) => { console.error(`Failed to stop the download task, Code: ${err.code}, message: ${err.message}`); }); console.info(`Succeeded in creating a download task. result: ${task.tid}`); - }).catch((err) => { + }).catch((err: BusinessError) => { console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`); }); ``` @@ -2838,17 +2822,16 @@ create(context: BaseContext, config: Config, callback: AsyncCallback<Task> **示例:** - ```js - let context; - let attachments = [{ - name: "reeateTest", - value: { - filename: "reeateTest.avi", - mimetype: "application/octet-stream", - path: "./reeateTest.avi", - } - }]; - let config = { + ```ts + let attachments: Array = [{ + name: "reeateTest", + value: { + filename: "reeateTest.avi", + mimeType: "application/octet-stream", + path: "./reeateTest.avi", + } + }]; + let config: request.agent.Config = { action: request.agent.Action.UPLOAD, url: 'http://127.0.0.1', title: 'reeateTest', @@ -2870,7 +2853,7 @@ create(context: BaseContext, config: Config, callback: AsyncCallback<Task> precise: false, token: "it is a secret" }; - request.agent.create(context, config, (err, task) => { + request.agent.create(this.context, config, (err: BusinessError, task: request.agent.Task) => { if (err) { console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`); return; @@ -2920,17 +2903,16 @@ create(context: BaseContext, config: Config): Promise<Task> **示例:** - ```js - let context; - let attachments = [{ - name: "reeateTest", - value: { - filename: "reeateTest.avi", - mimetype: "application/octet-stream", - path: "./reeateTest.avi", - } - }]; - let config = { + ```ts + let attachments: Array = [{ + name: "reeateTest", + value: { + filename: "reeateTest.avi", + mimeType: "application/octet-stream", + path: "./reeateTest.avi", + } + }]; + let config: request.agent.Config = { action: request.agent.Action.UPLOAD, url: 'http://127.0.0.1', title: 'reeateTest', @@ -2952,7 +2934,7 @@ create(context: BaseContext, config: Config): Promise<Task> precise: false, token: "it is a secret" }; - request.agent.create(context, config).then((task)=> { + request.agent.create(this.context, config).then((task: request.agent.Task) => { console.info(`Succeeded in creating a download task. result: ${task.config}`); }).catch((err) => { console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`); @@ -2989,8 +2971,8 @@ remove(id: string, callback: AsyncCallback<void>): void **示例:** - ```js - request.agent.remove("id", (err) => { + ```ts + request.agent.remove("id", (err: BusinessError) => { if (err) { console.error(`Failed to removing a download task, Code: ${err.code}, message: ${err.message}`); return; @@ -3031,10 +3013,10 @@ remove(id: string): Promise<void> **示例:** - ```js + ```ts request.agent.remove("id").then(() => { console.info(`Succeeded in removing a download task. `); - }).catch((err) => { + }).catch((err: BusinessError) => { console.error(`Failed to remove a download task, Code: ${err.code}, message: ${err.message}`); }); ``` @@ -3065,8 +3047,8 @@ show(id: string, callback: AsyncCallback<TaskInfo>): void **示例:** - ```js - request.agent.show("123456", (err, TaskInfo) => { + ```ts + request.agent.show("123456", (err: BusinessError, taskInfo: request.agent.TaskInfo) => { if (err) { console.error(`Failed to show a unload task, Code: ${err.code}, message: ${err.message}`); return; @@ -3106,10 +3088,10 @@ show(id: string): Promise<TaskInfo> **示例:** - ```js - request.agent.show("123456").then((TaskInfo) => { + ```ts + request.agent.show("123456").then((taskInfo: request.agent.TaskInfo) => { console.info(`Succeeded in showing a unload task.`); - }).catch((err) => { + }).catch((err: BusinessError) => { console.error(`Failed to show a unload task, Code: ${err.code}, message: ${err.message}`); }); ``` @@ -3141,8 +3123,8 @@ touch(id: string, token: string, callback: AsyncCallback<TaskInfo>): void **示例:** - ```js - request.agent.touch("123456", "token", (err, TaskInfo) => { + ```ts + request.agent.touch("123456", "token", (err: BusinessError, taskInfo: request.agent.TaskInfo) => { if (err) { console.error(`Failed to touch a unload task, Code: ${err.code}, message: ${err.message}`); return; @@ -3183,10 +3165,10 @@ touch(id: string, token: string): Promise<TaskInfo> **示例:** - ```js - request.agent.touch("123456", "token").then((TaskInfo) => { + ```ts + request.agent.touch("123456", "token").then((taskInfo: request.agent.TaskInfo) => { console.info(`Succeeded in touching a unload task. `); - }).catch((err) => { + }).catch((err: BusinessError) => { console.error(`Failed to touch a unload task, Code: ${err.code}, message: ${err.message}`); }); ``` @@ -3216,13 +3198,13 @@ search(filter: Filter, callback: AsyncCallback<Array<string>>): void **示例:** - ```js - let filter ={ - bundle:"com.example.myapplication", + ```ts + let filter: request.agent.Filter = { + bundle: "com.example.myapplication", action: request.agent.Action.UPLOAD, - mode:request.agent.Mode.BACKGROUND + mode: request.agent.Mode.BACKGROUND } - request.agent.search(filter, (err, data) => { + request.agent.search(filter, (err: BusinessError, data: Array) => { if (err) { console.error(`Failed to search a unload task, Code: ${err.code}, message: ${err.message}`); return; @@ -3261,15 +3243,15 @@ search(filter: Filter): Promise<Array<string>> **示例:** - ```js - let filter ={ - bundle:"com.example.myapplication", + ```ts + let filter: request.agent.Filter = { + bundle: "com.example.myapplication", action: request.agent.Action.UPLOAD, mode: request.agent.Mode.BACKGROUND } - request.agent.search(filter).then((data) => { + request.agent.search(filter).then((data: Array) => { console.info(`Succeeded in searching a unload task. `); - }).catch((err) => { + }).catch((err: BusinessError) => { console.error(`Failed to search a unload task, Code: ${err.code}, message: ${err.message}`); }); ``` @@ -3304,13 +3286,13 @@ query(id: string, callback: AsyncCallback<TaskInfo>): void **示例:** - ```js - request.agent.query("123456", (err, TaskInfo) => { + ```ts + request.agent.query("123456", (err: BusinessError, taskInfo: request.agent.TaskInfo) => { if (err) { console.error(`Failed to query a unload task, Code: ${err.code}, message: ${err.message}`); return; } - console.info(`Succeeded in querying a unload task. result: ${TaskInfo.uid}`); + console.info(`Succeeded in querying a unload task. result: ${taskInfo.uid}`); }); ``` @@ -3349,10 +3331,10 @@ query(id: string): Promise<TaskInfo> **示例:** - ```js - request.agent.query("123456",).then((TaskInfo) => { - console.info(`Succeeded in querying a unload task. result: ${TaskInfo.uid}`); - }).catch((err) => { + ```ts + request.agent.query("123456",).then((taskInfo: request.agent.TaskInfo) => { + console.info(`Succeeded in querying a unload task. result: ${taskInfo.uid}`); + }).catch((err: BusinessError) => { console.error(`Failed to query a unload task, Code: ${err.code}, message: ${err.message}`); }); ```