我正在尝试使用“ nativescript-background-http”。遇到错误时,我只会收到错误代码,而不会收到完整的响应,这会告诉我什么地方出错了。如何获得回复?
task.on("progress", progressHandler);
task.on("error", errorHandler);
task.on("responded", respondedHandler);
task.on("complete", completeHandler);
// event arguments:
// task: Task
// currentBytes: number
// totalBytes: number
function progressHandler(e) {
alert("uploaded " + e.currentBytes + " / " + e.totalBytes);
}
// event arguments:
// task: Task
// responseCode: number
// error: java.lang.Exception (Android) / NSError (iOS)
// response: net.gotev.uploadservice.ServerResponse (Android) / NSHTTPURLResponse (iOS)
function errorHandler(e) {
alert("received error " + e.responseCode + " code.");
var serverResponse = e.response;
console.log(JSON.stringify(serverResponse));
console.log(e.error);
console.log(e.response);
console.log(e.task);
}
// event arguments:
// task: Task
// responseCode: number
// data: string
function respondedHandler(e) {
alert("responded received " + e.responseCode + " code. Server sent: " + e.data);
}
// event arguments:
// task: Task
// responseCode: number
// response: net.gotev.uploadservice.ServerResponse (Android) / NSHTTPURLResponse (iOS)
function completeHandler(e) {
alert("received " + e.responseCode + " code");
var serverResponse = e.response;
}
// event arguments:
// task: Task
function cancelledHandler(e) {
alert("upload cancelled");
}
}
”已响应仅在成功时给我答复,而在出现错误时则不会给我答复。