我在移动应用程序开发中在插件 NativeScript/nativescript-background-http 的错误块(回调)中获取服务器响应以上传文件时遇到问题。基于错误服务器响应将执行其他操作
插件 nativescript-background-http 的错误回调
将文件上传到服务器,我已经能够在响应的回调中读取响应,但这是成功的情况。
task.on("responded", (e:any)=>{
//response
let response= JSON.parse(e.data)
});
如果出现错误,它将无法正常工作
let task = session.multipartUpload(params, request);
task.on("error", event => {
console.dir(event);
console.log(JSON.stringify(event))
console.log(event.responseCode);
console.log(event.response)
// console.log((JSON.parse(event.response))
});
结果-
事件名称:“错误” JS:对象:{ JS:“_observers”:{ JS:
“完成”:[ JS:{} JS:],JS:“错误”:[ JS:{} JS:],JS:“回应“:[ JS:{} JS:] JS:},JS:“_session”:{ JS:“_id”:“文件上传” JS:},JS:“_id”:“文件上传{1} ", JS: "_description": "日志文件", JS: "_upload": 4309, JS: "_totalUpload": 4309, JS: "_status": "error" JS: } JS: error: "null" JS: responseCode:“400” JS:响应:net.gotev.uploadservice.ServerResponse@73e7f34
预期:-响应:{ isSuccess:false, msg:'Token-Invalid' }