diff --git a/pages/API/unicloud-import-object/unicloud-import-object.test.js b/pages/API/unicloud-import-object/unicloud-import-object.test.js
index 5e8662bdad80ac85c2ea0331a69d39a4032ee8ad..b9caa87141b055c6933cffdcb96b6c240af590e6 100644
--- a/pages/API/unicloud-import-object/unicloud-import-object.test.js
+++ b/pages/API/unicloud-import-object/unicloud-import-object.test.js
@@ -12,6 +12,7 @@ describe('unicloud-import-object', () => {
it('importObject', async () => {
await page.callMethod('addTodo')
await page.callMethod('fail')
+ await page.callMethod('failWithNumberErrCode')
await page.callMethod('success')
const {
@@ -20,12 +21,14 @@ describe('unicloud-import-object', () => {
returnTodoTitle,
returnTodoContent,
failErrCode,
+ failWithNumberErrCode,
successErrCode,
} = await page.data()
expect(returnTodoTitle).toBe(todoTitle)
expect(returnTodoContent).toBe(todoContent)
expect(failErrCode).toBe('TEST_ERROR_CODE')
+ expect(failWithNumberErrCode).toBe(-1)
expect(successErrCode).toBe(0)
})
diff --git a/pages/API/unicloud-import-object/unicloud-import-object.uvue b/pages/API/unicloud-import-object/unicloud-import-object.uvue
index 8ee4f6cb76293beb8bd88ef8e09631090e86640a..e26872212480b31c74a99ce95a6d13533e9a0211 100644
--- a/pages/API/unicloud-import-object/unicloud-import-object.uvue
+++ b/pages/API/unicloud-import-object/unicloud-import-object.uvue
@@ -14,6 +14,9 @@
+
+
+
@@ -34,6 +37,7 @@
returnTodoTitle: '',
returnTodoContent: '',
failErrCode: '',
+ failWithNumberErrCode: 0,
successErrCode: -1,
isUniTest: false
}
@@ -104,6 +108,24 @@
}
})
},
+ async failWithNumberErrCode(){
+ const todo = uniCloud.importObject('todo', {
+ customUI: this.isUniTest
+ })
+ await todo.fail().then((res : UTSJSONObject) => {
+ this.notify('todo.fail应调用失败,此处错误的触发了成功回调', '错误')
+ console.log('todo.fail: ', res);
+ }).catch((err : any | null) => {
+ const error = err as UniCloudError
+ this.failWithNumberErrCode = error.errCode as number
+ console.error(error)
+ if (this.isUniTest) {
+ uni.showToast({
+ title: error.errMsg
+ })
+ }
+ })
+ },
async success() : Promise {
const todo = uniCloud.importObject('todo', {
customUI: this.isUniTest
diff --git a/uniCloud-aliyun/cloudfunctions/todo/index.obj.js b/uniCloud-aliyun/cloudfunctions/todo/index.obj.js
index 4680891d9042b8f8c3623dbe3cdab2121986ad4e..51a325949b8367f608371f5499d804c216628cb0 100644
--- a/uniCloud-aliyun/cloudfunctions/todo/index.obj.js
+++ b/uniCloud-aliyun/cloudfunctions/todo/index.obj.js
@@ -31,6 +31,12 @@ module.exports = {
errMsg: '[预期内的报错]执行失败',
}
},
+ async failWithNumberErrCode() {
+ return {
+ errCode: -1,
+ errMsg: '[预期内的报错]执行失败',
+ }
+ },
async success() {
return {
errCode: 0,